0

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!

  • Not sure what the question is here...you can use whatever you like to read in a json file and then update those values...a web page, command line program, rest api, etc...take your pick... – Zack Macomber Feb 28 '22 at 19:28
  • 2
    I see that you are a fresh member. First of all, Welcome aboard ! Secondly, this is not a forum where you can just post a specific task and expect answers. Instead, you must generalize your question so others can benefit from it, also it would be easier to find an answer if you ask for directions to the solution rather than a tailored answer just for you. What seems to be helpful to you is a tool called "templating engine". There are frameworks in Java that does what you are expecting with a very easy to use API. Have you ever looked around for such thing ? – alegria Feb 28 '22 at 19:51
  • @alegria Hi, thanks for the reply. I will look into templating engine. Also, this json is just an example to explain what is the requirement in general! – Nikhil Vernekar Feb 28 '22 at 20:04

0 Answers0