4

Is anyone aware of a JSON-XPath style library that allows data manipulation; update, delete, create, etc...

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

I've looked into the following, but none allow altering the content.

JPath

JSONQuery

JSONiJ

2
  • This implementation of JsonPath for Java seems fine: github.com/nebhale/JsonPath Commented Apr 17, 2013 at 15:58
  • @AlexisDufrenoy Can you reply as an answer and show how this implementation (com.nebhale.jsonpath) has modification/write capabilities? Commented Aug 15, 2014 at 13:38

3 Answers 3

2

JsonPath (im using 2.2.0) now allows the manipulation of JSON data. e.g.

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

results in {"drink":"beer"}

Sign up to request clarification or add additional context in comments.

Comments

0

JSON was not meant to be a database.

If you want to store your data in the JSON format;

  • Read the JSON records into your Java application and create data objects.
  • Modify the data objects in the Java application.
  • When the application closes, write the JSON records back out.

You'd be better off using an actual database, relational or NoSQL, to store your data, and write JSON records when they're needed.

Comments

0

You might want to have a look at this library I developped to be able to use XML libraries to manipulate JSON: https://github.com/bhabegger/json-n-xml/

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

(JSON may not be meant to be a database but you do have occasions where you just want simple modifications.)

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.