0

I would like to send multilevel JSON object as GET request parameter in JavaScript. To serialize I use this:

json_object = {
    key_a: {
        key_aa: 1,
        key_ab: 2,
    },
    key_b: {
        key_ba: 1,
        key_bb: 2,
    },
}
var encoded_json = jQuery.param( json_object );

and receive:

key_a%5Bkey_aa%5D=1&key_a%5Bkey_ab%5D=2&key_b%5Bkey_ba%5D=1&key_b%5Bkey_bb%5D=2

So, next, in python I would like to decode this string:

print(parse_qs(json))

and I receive:

{
    'key_a[key_aa]': ['1'], 
    'key_a[key_ab]': ['2'], 
    'key_b[key_ba]': ['1'], 
    'key_b[key_bb]': ['2']
}

How can I transform this dictionary to form similar to input JSON object?

Esato
  • 127
  • 1
  • 9

1 Answers1

0

The answer of my question is: use JSON.stringify

serialized_object = JSON.stringify(object) 

to serialize JavaScript object and next, use

json.loads(serialized_object)

in Python to get dictionary in case of POST request using.

Esato
  • 127
  • 1
  • 9