Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse JavaScript variable with Python

How can I convert a JavaScript variable (not JSON format) into 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"],
}
like image 330
jack Avatar asked Sep 11 '10 06:09

jack


1 Answers

This format looks just like the input in this question. Try adapting the pyparsing parser I posted there.

like image 175
PaulMcG Avatar answered Sep 25 '22 01:09

PaulMcG