All Projects → flipkart-incubator → Zjsonpatch

flipkart-incubator / Zjsonpatch

Licence: apache-2.0
This is an implementation of RFC 6902 JSON Patch written in Java

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Zjsonpatch

Fehelper
😍FeHelper--Web前端助手(Awesome!Chrome & Firefox & MS-Edge Extension, All in one Toolbox!)
Stars: ✭ 3,880 (+971.82%)
Mutual labels:  json
Hashover Next
This branch will be HashOver 2.0
Stars: ✭ 353 (-2.49%)
Mutual labels:  json
Newton Api
➗ A really micro micro-service for advanced math.
Stars: ✭ 358 (-1.1%)
Mutual labels:  json
Cppwebframework
​The C++ Web Framework (CWF) is a MVC web framework, Open Source, under MIT License, using C++ with Qt to be used in the development of web applications.
Stars: ✭ 348 (-3.87%)
Mutual labels:  json
Ws
⚠️ Deprecated - (in favour of Networking) ☁️ Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
Stars: ✭ 352 (-2.76%)
Mutual labels:  json
Jqview
simplest possible native GUI for inspecting JSON objects with jq
Stars: ✭ 355 (-1.93%)
Mutual labels:  json
Allorigins
👽 Pull contents from any page as JSON via API
Stars: ✭ 343 (-5.25%)
Mutual labels:  json
Threatmapper
Identify vulnerabilities in running containers, images, hosts and repositories
Stars: ✭ 361 (-0.28%)
Mutual labels:  circleci
Log
Structured Logging Made Easy
Stars: ✭ 350 (-3.31%)
Mutual labels:  json
Shop
🛍🛒 Full-stack React/Prisma/TS/GraphQL E-Commerce Example
Stars: ✭ 359 (-0.83%)
Mutual labels:  circleci
Bad json parsers
Exposing problems in json parsers of several programming languages.
Stars: ✭ 351 (-3.04%)
Mutual labels:  json
Nodb
NoDB isn't a database.. but it sort of looks like one.
Stars: ✭ 353 (-2.49%)
Mutual labels:  json
Arrow
🏹 Parse JSON with style
Stars: ✭ 355 (-1.93%)
Mutual labels:  json
Velocypack
A fast and compact format for serialization and storage
Stars: ✭ 347 (-4.14%)
Mutual labels:  json
Ngrest
Fast and easy C++ RESTful WebServices framework
Stars: ✭ 357 (-1.38%)
Mutual labels:  json
Json
C++ header-only JSON library
Stars: ✭ 343 (-5.25%)
Mutual labels:  json
Tfnotify
A CLI command to parse Terraform execution result and notify it to GitHub
Stars: ✭ 353 (-2.49%)
Mutual labels:  circleci
Pmjson
Pure Swift JSON encoding/decoding library
Stars: ✭ 362 (+0%)
Mutual labels:  json
Schema
📐 Validating data structures against a given Schema.
Stars: ✭ 359 (-0.83%)
Mutual labels:  json
5e Database
Database for the D&D 5th Edition API
Stars: ✭ 354 (-2.21%)
Mutual labels:  json

CircleCI Join the chat at https://gitter.im/zjsonpatch/community

This is an implementation of RFC 6902 JSON Patch written in Java.

Description & Use-Cases

  • Java Library to find / apply JSON Patches according to RFC 6902.
  • JSON Patch defines a JSON document structure for representing changes to a JSON document.
  • It can be used to avoid sending a whole document when only a part has changed, thus reducing network bandwidth requirements if data (in JSON format) is required to send across multiple systems over network or in case of multi DC transfer.
  • When used in combination with the HTTP PATCH method as per RFC 5789 HTTP PATCH, it will do partial updates for HTTP APIs in a standard way.

Compatible with : Java 7+ versions

Code Coverage

Package Class, % Method, % Line, %
all classes 100% (6/ 6) 93.6% (44/ 47) 96.2% (332/ 345)

Complexity

  • To find JsonPatch : Ω(N+M) ,N and M represents number of keys in first and second json respectively / O(summation of la*lb) where la , lb represents JSON array of length la / lb of against same key in first and second JSON ,since LCS is used to find difference between 2 JSON arrays there of order of quadratic.
  • To Optimize Diffs ( compact move and remove into Move ) : Ω(D) / O(D*D) where D represents number of diffs obtained before compaction into Move operation.
  • To Apply Diff : O(D) where D represents number of diffs

How to use:

Current Version : 0.4.11

Add following to <dependencies/> section of your pom.xml -

<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>{version}</version>

API Usage

Obtaining JSON Diff as patch

JsonNode patch = JsonDiff.asJson(JsonNode source, JsonNode target)

Computes and returns a JSON patch from source to target, Both source and target must be either valid JSON objects or arrays or values. Further, if resultant patch is applied to source, it will yield target.

The algorithm which computes this JsonPatch currently generates following operations as per RFC 6902 -

  • add
  • remove
  • replace
  • move
  • copy

Apply Json Patch

JsonNode target = JsonPatch.apply(JsonNode patch, JsonNode source);

Given a patch, it apply it to source JSON and return a target JSON which can be ( JSON object or array or value ). This operation performed on a clone of source JSON ( thus, the source JSON is unmodified and can be used further).

To turn off MOVE & COPY Operations

EnumSet<DiffFlags> flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone()
JsonNode patch = JsonDiff.asJson(JsonNode source, JsonNode target, flags)

Example

First Json

{"a": 0,"b": [1,2]}

Second json ( the json to obtain )

 {"b": [1,2,0]}

Following patch will be returned:

[{"op":"move","from":"/a","path":"/b/2"}]

here "op" specifies the operation ("move"), "from" specifies the path from where the value should be moved, and "path" specifies where value should be moved. The value that is moved is taken as the content at the "from" path.

Apply Json Patch In-Place

JsonPatch.applyInPlace(JsonNode patch, JsonNode source);

Given a patch, it will apply it to the source JSON mutating the instance, opposed to JsonPatch.apply which returns a new instance with the patch applied, leaving the source unchanged.

Tests:

  1. 100+ selective hardcoded different input JSONs , with their driver test classes present under /test directory.
  2. Apart from selective input, a deterministic random JSON generator is present under ( TestDataGenerator.java ), and its driver test class method is JsonDiffTest.testGeneratedJsonDiff().

*** Tests can only show presence of bugs and not their absence ***

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].