1 year ago

#235624

test-img

Nikhil Vernekar

Create new json file using json template file

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": "michael.lawson@reqres.in",
            "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": "updated@email.com",
            "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!

java

json

jackson

fasterxml

json-simple

0 Answers

Your Answer

Accepted video resources