I'm trying to find a parser for python that can parse the data structure (to a python dictionary) that is written below (this data structure was taken from var variable in javascript).
{
a: "a",
b: 54,
c: [
{
d: "d",
e: false
},
{
f: "f"
}
]
};
1 Answer 1
demjson.decode()
import demjson
# from
js_obj = '{x:1, y:2, z:3}'
# to
py_obj = demjson.decode(js_obj)
jsonnet.evaluate_snippet()
import json, _jsonnet
# from
js_obj = '{x:1, y:2, z:3}'
# to
py_obj = json.loads(_jsonnet.evaluate_snippet('snippet', js_obj))
ast.literal_eval()
import ast
# from
js_obj = "{'x':1, 'y':2, 'z':3}"
# to
py_obj = ast.literal_eval(js_obj)
answered Oct 10, 2017 at 22:00
njha
1,1181 gold badge13 silver badges27 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
njha
I'm not sure if I'm supposed to somehow link the answer I got this from, so I copied/pasted instead. Source: stackoverflow.com/questions/24027589/…
Koko
The ; in the end needed to be removed from my string and it will work with demjson, Thanks.
Milan
Unfortunately none of these tools can be installed anymore
default
json, which is Javascript-Object-notation after all...a,betc would have to be strings.