Removing root node in json in Python

Viewed 201

I have a json data stored in a variable.

Json Data:

{ "XYZ": { "abc":[{....}] } }

From above JSON Data, I should not have XYZ node. I need JSON Data as

{ "abc":[{....}] }

How can I remove using Python?

Thanks a lot!

1 Answers

You want to look up the dictionary via it's key ("XYZ") and assign it to a new variable:

data = request_data.get("XYZ")

this will return None if there is no "XYZ" key, but if you know the "XYZ" key is always going to be there you can lookup like so:

data = requests_data["XYZ"]

Related