-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for parsing JSON #15
Comments
Actually you can parse json with js2xml but it's really ugly and you need to wrap it with a variable assignment:
Will give this:
which works but is really ugly because it's using property, object as node names instead of original names from the json. In otherwords it's parsing javascript from what clearly is a json.
result:
It seems to be quite simple and maybe we could adapt it into js2xml? |
There's also this: https://github.com/quandyfactory/dicttoxml which seems to be a bit more popular but it's essentially the same as dict2xml it just adds types to nodes.
Personally I don't like that it wraps every list element in |
Related |
@pawelmhm , I think using js2xml to query data from JSON is out of scope of what this library tries to do. js2xml is very handy when extracting strings, numbers, JavaScript objects and arrays from assignments and function arguments (when writing regexes for them is tedious) "XPath for JSON" is kind of a different (yet interesting) use-case. As @Granitas mentions, the AST-like tree that js2xml outputs for a JSON dict is not that easy to work with. Which is why js2xml has methods to convert JavaScript objects to dicts. I would personally leave the querying of data inside dicts out of js2xml. As for why parsing a JSON object directly, without an assignment, does not work, it has to do with how slimit interprets snippets of code. May be worth fixing. |
Closing this issue as traversing JSON using XPaths is not the purpose of js2xml. |
Sometimes I'm dealing with deeply nested JSON and I'd like to parse it with xpaths. I know I can use JMESPATH but I dont like JMESPATH syntax, I'm used to xpaths. Also seems like some features of xpaths are not supported by Jmespath, e.g. I can't do recursive traversal, so I can't write
//mynode/text()
in Jmes I have to doroot.foo.bar[].foo2.bar2.product.mynode
.It seems like JSON is currently not supported by js2xml, e.g. something like this:
fails.
Is there some way to add support for JSON parser to js2xml? This would probably require conversion from Python dictionary to xml, seems like there are packages that do this https://github.com/delfick/python-dict2xml so maybe we could learn something from them.
The text was updated successfully, but these errors were encountered: