0

I am using python's json module to pretty print a json String which looks like below

"{"content" : "{"key" : "value"}","otherContent: "{"key2":"value"}"}"

i want it to look like so when i print it

{ 
 c1: {
       key: value
     },
 c2: {
        key2: value
     }
}

or something similar to this format, how can i achieve this ?

1 Answers1

0

I had to reformat your json a bit by adding some square brackets, but this works:

json_string = '{"content": [{"key": "value"}], "otherContent": [{"key2": "value"}]}'

loaded_json = json.loads( json_string )

print(json.dumps(loaded_json , sort_keys=True, indent=4))

Output:

{
    "content": [
        {
            "key": "value"
        }
    ],
    "otherContent": [
        {
            "key2": "value"
        }
    ]
}
LucyDrops
  • 539
  • 5
  • 15
Mark Moretto
  • 2,344
  • 2
  • 15
  • 21