How to get values from keys from JSON

raffzwo :

I'm trying to get some values from a JSON file in Python to create a curl command with these values from the file.

The values that i am looking for are "alarm-id" and "sequence-id".

The JSON file looks like this:

{
  "data": [
    {
      "attributes": {
        "alarm-id": "3672400101833445418",
        "sequence-id": "1573135238000"
      }
    }
  ]
}

I've tried get() but i cant figure out how to use this correctly.

If you need more information just ask.

Thanks in advance!

Best regards

Gamopo :

This should work for you

import json

data = json.loads(#yourJSON)
for attribute in data['data']:
    print(attribute['attributes']['alarm-id'])
    print(attribute['attributes']['sequence-id'])

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=19405&siteId=1