Skip to content
Advertisement

Creating custom JSON from existing JSON using Python

(Python beginner alert) I am trying to create a custom JSON from an existing JSON. The scenario is –

I have a source which can send many set of fields but I want to cherry pick some of them and create a subset of that while maintaining the original JSON structure.

Original Sample

JavaScript

Here the sData array tag has got few tags out of which I want to keep only 24 and get rid of the rest. I know I could use element.pop() but I cannot go and delete a new incoming field every time the source publishes it. Below is the expected output –

Expected Output

JavaScript

I myself took reference from How can I create a new JSON object form another using Python? but its not working as expected. Looking forward for inputs/solutions from all of you gurus. Thanks in advance.

Advertisement

Answer

Kind of like this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement