Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python parsing strange JSON data

How should I parse (with Python3) data in this "unusual" format?
As you can see inside the "variables" dictionary the data that is in capitals has no label, it is provided as a literal. Therefore when I loop over the entries inside "variables" all I get is the strings in capitals, nothing else. I need, obviously, to get the capitals plus the value inside it.

    {
    "variables": {
    "ABSENCE_OSL_PROD": {
      "value": "REZWWnBTejN5Ng=="
    },
    "ACTION_OSL_INT": {
      "value": "S0RXSVNTbmFhNw=="
    },
    "ACTION_OSL_PROD": {
      "value": "RUJCaDJGnmFnUg=="
    },
    "API_STORE_OSL_INT": {
      "value": "U3lxaVhogWtIcg=="
    }
  },
  "id": 4,
  "type": "Vsts"
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To load the variables inside variables in the local variable space:

data =    {
    "variables": {
    "ABSENCE_OSL_PROD": {
      "value": "REZWWnBTejN5Ng=="
    },
    "ACTION_OSL_INT": {
      "value": "S0RXSVNTbmFhNw=="
    },
    "ACTION_OSL_PROD": {
      "value": "RUJCaDJGnmFnUg=="
    },
    "API_STORE_OSL_INT": {
      "value": "U3lxaVhogWtIcg=="
    }
  },
  "id": 4,
  "type": "Vsts"
}

for variable_name, variable_content in data['variables'].items():
    locals()[variable_name] = variable_content['value']

print(ABSENCE_OSL_PROD)
# prints "REZWWnBTejN5Ng=="
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading