libyang
libyang copied to clipboard
how to xmltojson by yanglint?
how to change xml to json by yanglint?Is there an example of this? Thanks!
./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.
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.