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", "birth_year", and "current_year".
I want to add a new field "age" to each object, calculated as the difference between "current_year" and "birth_year".
I want to write the transformed data to a new JSON file named "transformed_data.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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!