Javascript variable with python

How to convert a JavaScript variable (not JSON format) to a python variable?

Example JavaScript variable:

{
    title: "TITLE",
    name: "NAME",
    active: false,
    info: {
        key1: "value1",
        dict1: {
            sub_key1: "sub_value1",
            sub_key2: "sub_value2",
        },
        dict2: {
            sub_key3: "sub_value3",
            sub_key4: "sub_value4",
            sub_key5: "sub_value5"
        },
    },
    list1: ["element1", "element2", "element2"],
}
+5
source share
2 answers

This format looks like an input to this question . Try to adapt the pyparsing parser that I posted there.

+4
source

Convert it to JSON and read in python.

I really don’t understand what is the problem?

eg. JSON.stringifygives

{"title":"TITLE","name":"NAME","active":false,"info":{"key1":"value1","dict1":{"sub_key1":"sub_value1","sub_key2":"sub_value2"},"dict2":{"sub_key3":"sub_value3","sub_key4":"sub_value4","sub_key5":"sub_value5"}},"list1":["element1","element2","element2"]}

What can be read by the python json module, so the question is where do you get javascript from and why can't you convert it to JSON?

: javascript, - , javascript , . spidermonkey ( firefox), rhino, V8 ( google chrome) Windows WSH. javascript-, javascript, python, .

, .

python-spidermonkey

+1

All Articles