libyang icon indicating copy to clipboard operation
libyang copied to clipboard

how to xmltojson by yanglint?

Open zyboy2000 opened this issue 2 years ago • 2 comments

how to change xml to json by yanglint?Is there an example of this? Thanks!

zyboy2000 avatar Aug 09 '23 05:08 zyboy2000

./yanglint -h

...

  -f FORMAT, --format=FORMAT
                Convert input into FORMAT. Supported formats: 
                yang, yin, tree, info and feature-param for schemas,
                xml, json, and lyb for data.

It says convert input. So for example you can:

$ cat ../tests/yanglint/data/modleaf.xml
<lfl xmlns="urn:yanglint:modleaf">7</lfl>
$ ./yanglint -f json ../tests/yanglint/data/modleaf.xml ../tests/yanglint/modules/modleaf.yang
{
  "modleaf:lfl": 7
}

Or you can use the interactive mode:

$ ./yanglint
> add ../tests/yanglint/modules/modleaf.yang
> data -f json ../tests/yanglint/data/modleaf.xml
{
  "modleaf:lfl": 7
}

Also note the -I FORMAT, --in-format=FORMAT and -o OUTFILE, --output=OUTFILE parameters, which may also be useful for you.

lePici avatar Aug 09 '23 06:08 lePici

You can see more examples of using yanglint in the tests/yanglint/non-interactive directory in the tests, which are written in tcl language, but they might help you too. Interactive tests are in the tests/yanglint/interactive directory. However, you can find much more readable examples in the tools/lint/examples/README.md file.

lePici avatar Aug 09 '23 06:08 lePici