-3

I have a json file as below and now I need to update the pincode value Everytime before using and use the updated json file for processing,how can I achieve the same using Java?

{ 
    "Name":"Ramesh",
    "City":"Bangalore",
    "Address": {
        " Pincode":56010
    }
}
Hayes Roach
  • 121
  • 10
umesh
  • 1
  • 3
  • 1
    You must first parse the JSON data into a usable datatype. Then you update the value to whatever you need and then send that value back. – Hayes Roach Jul 10 '19 at 18:43
  • This is all detailed here: https://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/ – David Brossard Jul 10 '19 at 18:47

1 Answers1

0

Umesh, My suggestion are listed as :

  1. Open the file, read the content
  2. Convert that json to object mapper(Jackson ObjectMapper).
  3. Close the file.
  4. Modify the Mapper Object with pincode as per your business
  5. The convert the object mapper to json string
  6. Open the same file to write the modify json string.
prashantr
  • 20
  • 5