this is a very specific request, and for that i apologise, but i am at a loss for what to do..
for a javascript project i am working on i want to be able to parse javascript with python and i found this implementation`port of the original narcissus called pynarcissus:
https://github.com/jtolds/pynarcissus
it is a straightforward tool: clone into folder, then run the "./jsparser3.py /SOME/JS/FILE.js", and stdout shows the class structure of the parsed js
the problem for me is the information is buried in the python class structure.. something with which i thought i had a solid understanding thereof but now am thinking i am only vaguely competent in.. and i want the output to be in JSON
i have tried to mine the data out but each time the JSON is invalid
my question is how would you go about doing something like this? i'd appreciate any specifics because the project contains nested classes of disparate types creating what seems to be a wholly unique problem
here are my attempts:
* i took the return value for parse() and created a function that descends through the class structure returning values based on their type: 'str', 'int', 'bool', 'NoneType', 'list', 'dict', '__main__.Node', '__main__.Tokenizer', '__main__.Object'; but the returned object is missing some properties in the classes, ie 'type', while retaining others like 'type_', also tokenizer always contains the same values
* i took the output of the __str__ function that the program prints to stdout, removed the clear and copy functions and the tokenizer: [object Object], then tried to manually add in double quotes where necessary to make the output a valid JSON object.. a few problems here, first off ignoring the tokenizer object seems like i am missing out on vital information, and the other problem was that sometimes there is "value" : "{" and sometimes there is "value" : { .. }, after completing the work the JSON was invalid
* assuming the issue lied in the "value" : { .. } issue i resolved to add a new function identical the the __str__ function but instead of printing just s values, it would print "s" where necessary.. now, i could differentiate between "value": "{" and "value" : "{ .. }" but i would have to go through and manually remove the quotes around objects.. after doing so the JSON was invalid
* i've tried every copy'pasta solution for python class to json from the stacks but the nested aspect of the classes along with the changing types add complexity.. some properties lack a .__dict__ even when the type is "<class 'dict'>" so the one'method'fits'all lambda solutions fail
..
i asked on the stacks ::
http://stackoverflow.com/questions/3...output-to-json
as well as placed an issue ::
https://github.com/jtolds/pynarcissus/issues/6
thanks for the time and thought, here's hoping..