Skip to content
Advertisement

How to replace a value of the given key path in dynamic json object using java

I have dynamic JSONs and their key-path, I need to change the values of the Json on received key paths

As an example, in have below JSON and key (cars.car1)

JavaScript

I need to change the value of cars.car1. as “Benz”. Also Please Note JSON body and its keys will change from time to time.

As an example, next time I may get a totally different JSON body with related key.

The key for the below JSON is: errors.source.pointer (Need to change the value of the given key)

JavaScript

Any idea to do this with Java

Advertisement

Answer

Through below code able to replace or remove the given item.

JavaScript
Advertisement