JsonPatch is a format for storing a sequence of operations that has to be applied on the target json structure. The following operations can be stored in JsonPath and operated on json structure 1) add 2) remove 3) replace 4) move 5) copy 6) test Java jdk provides api for creating JsonPatch. The post explains…… Continue reading Simple JsonPatch Example
Category: JSONP
Operations that can be performed using JSON Pointer
This post explains the operations that can be performance on json data with the help of new JSONP 1.1 api. As we know from our previuos post JSON Pointer is a string syntax used to identify and locate a particular field or property in a json file. Once identified and located we can perform the…… Continue reading Operations that can be performed using JSON Pointer
JSON Pointer Example
This post explains JSON Pointer with an example. JSON Pointer is a standard that defines a string syntax, which can used to access a particular field or key value in the entire json document. For example in the below json document json document { “firstName”: “Duke”, “lastName”: “Java”, “age”: 18, “streetAddress”: “100 Internet Dr”, “city”:…… Continue reading JSON Pointer Example
Reading json data in streaming way
This post explains how to read json data as a stream. The previous post explains the same using JsonReader. The difference is that to use JsonReader we need to build the entire object (which represents json data) in memory. Whereas with JsonParser we dont need to build the entire object. The below code explains how…… Continue reading Reading json data in streaming way
Writing JSON Data in a streaming way
This post explains how to write json data to a file using JsonGenerator. The previous post explains the same using JsonWriter. The difference is that to use JsonWriter we need to build the entire object (which represents json data) in memory before writing to a file. Whereas with JsonGenerator we dont need to build the…… Continue reading Writing JSON Data in a streaming way
Updating an existing json data
This post explain how we can update an existing json data stored in a file. For example purpose lets create a json file named jsondata1.txt with the following data jsondata1.txt { “firstName”:”John”, ”lastName”:”McClane”, ”age”:”28″, ”address”:{ “street”:”street1″, ”city”:”city1″, ”state”:”state1″, ”country”:”country1″, ”postalCode”:”12345″ }, “Phones”:[{“Mobile”:”111-111-1111″},{“Home”:”222-222-2222″}] } The code is as shown below package objectmodel; import java.io.FileReader; import java.io.FileWriter;…… Continue reading Updating an existing json data
How to write json data to a file
This post explains how to write json data to a file. We will store the below json structure in the file { “firstName”:”John”, ”lastName”:”McClane”, ”age”:”28″, ”address”:{ “street”:”street1″, ”city”:”city1″, ”state”:”state1″, ”country”:”country1″, ”postalCode”:”12345″ }, “Phones”:[{“Mobile”:”111-111-1111″},{“Home”:”222-222-2222″}] } Note: The output will not be formatted package objectmodel; import java.io.FileWriter; import javax.json.Json; import javax.json.JsonArrayBuilder; import javax.json.JsonBuilderFactory; import javax.json.JsonObject; import javax.json.JsonObjectBuilder;…… Continue reading How to write json data to a file
How to read a json file in java
Create a txt file named jsondata.txt with the below data { “firstName”: “Duke”, “lastName”: “Java”, “age”: 18, “streetAddress”: “100 Internet Dr”, “city”: “JavaTown”, “state”: “JA”, “postalCode”: “12345”, “phoneNumbers”: [ { “Mobile”: “111-111-1111” }, { “Home”: “222-222-2222” } ] } Below is the java code which will read the above text file Main Code package objectmodel;…… Continue reading How to read a json file in java