Question: How can I use Python to read data from a JSON file, transform the data by adding a new field based on existing fields, and
How can I use Python to read data from a JSON file, transform the data by adding a new field based on existing fields, and write the transformed data back to a new JSON file?
Details:
I have a JSON file named "data.json" with an array of objects. Each object contains fields "name", "birthyear", and "currentyear".
I want to add a new field "age" to each object, calculated as the difference between "currentyear" and "birthyear".
I want to write the transformed data to a new JSON file named "transformeddata.json".
Can you provide a Python script to accomplish this?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
