0

I have the followin json and I want to load it in python without overwriting the multiple index:

{
  "data": [
    {
      "HOSTNAME": "test",
      "STATUS": "200",
      "TYPE": "linux",
      "CPU": {
        "SRC": "src",
        "LINK": "link",
        "LABEL": "cpu"
      },
      "CPU": {
        "SRC": "src",
        "LINK": "link",
        "LABEL": "cpu"
      },
      "MEMORY": {
        "SRC": "src",
        "LINK": "link",
        "LABEL": "cpu"
      }
    }
  ]
}

I'm using:

 json.loads("HERE COMES THE JSON")

The result overwrite the index, example:

 {
 data:
     [
     {
      "HOSTNAME": "test",
      "STATUS": "200",
      "TYPE": "linux",
      "CPU": {
             "SRC": "src",
             "LINK": "link",
             "LABEL": "cpu"
             },
      "MEMORY": {
                "SRC": "src",
                "LINK": "link",
                "LABEL": "cpu"
                }
      }
      ]
 }

Note that is only one CPU.

Is there any way to not overwrite it?

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
brunozrk
  • 773
  • 1
  • 7
  • 14

1 Answers1

3

The file is not valid JSON and you cannot use the json module to parse it the way you want to.

UPDATE: it seems that it's possible after all with the help of the object_pairs_hook parameter to json.load(s); see SimpleJson handling of same named entities for an example.

Community
  • 1
  • 1
Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111