Json java manipulation

Does anyone know of a JSON-XPath style library that allows you to manipulate data; update, delete, create, etc.

JsonPath.write(json, "$.store.book[*].author", value); 

I looked at the following, but no one allows me to change the content.

Jpath

Jsonquery

JSONiJ

+4
source share
3 answers

JsonPath (im using 2.2.0) now allows you to manipulate JSON data. eg.

  String jsonData = "{\"drink\":\"juice\"}"; JsonPath.parse(jsonData).set("$.drink", "beer").jsonString(); 

leads to {"drink":"beer"}

+2
source

JSON was not supposed to be a database.

If you want to save the data in JSON format,

  • Read the JSON entries in your Java application and create data objects.
  • Change data objects in a Java application.
  • When the application closes, write down the JSON entries.

You are better off using a real database, relational or NoSQL, to store your data and write JSON records when needed.

0
source

You might want to take a look at this library that I developed to be able to use XML libraries to control JSON: https://github.com/bhabegger/json-n-xml/

It parses JSON in a DOM structure that you can manipulate with standard XML tools, and then allows you to serialize back to json.

(JSON may not be a database, but you have cases where you just need simple modifications.)

Hope this helps.

0
source

All Articles