Create new json file using json template file

414 Views Asked by At

I have a json template file. Using java program, I need to read the template and create a new json file with updated values.

Example Template json example:

{
    "page": 2,
    "per_page": 6,
    "total": 12,
    "total_pages": 2,
    "data": [
        {
            "id": 7,
            "email": "[email protected]",
            "first_name": "Michael",
            "last_name": "Lawson",
            "avatar": "https://reqres.in/img/faces/7-image.jpg"
        }
    ],
    "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
    }
}

Expected output json file: (updated page,first name, last name, email, text)

{
    "page": 3,
    "per_page": 6,
    "total": 12,
    "total_pages": 2,
    "data": [
        {
            "id": 7,
            "email": "[email protected]",
            "first_name": "MichaelPatric",
            "last_name": "lastName",
            "avatar": "https://reqres.in/img/faces/7-image.jpg"
        }
    ],
    "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "text udpated"
    }
}

Need a generic java code/logic using which we can modify any values from template json and create new output json file. Thanks in advance!

0

There are 0 best solutions below