Example schema: JSON Patch

790 views
Skip to first unread message

Francis Galiegue

unread,
Feb 3, 2013, 5:33:41 AM2/3/13
to json-...@googlegroups.com
JSON Patch is a very powerful IETF draft allowing to patch any JSON
value. Its operations are dead simple. So simple in fact that it took
me 10 minutes to write this:

https://github.com/fge/json-schema-validator/blob/master/src/main/resources/json-patch.json

Link to the draft:

http://tools.ietf.org/html/draft-ietf-appsawg-json-patch-10

Given its simplicity, now you understand why I see its uses for JSON Schema.

I will certainly implement it as a means to modify them!

--
Francis Galiegue, fgal...@gmail.com
Try out your JSON Schemas: http://json-schema-validator.herokuapp.com

Geraint (David)

unread,
Feb 3, 2013, 9:18:42 AM2/3/13
to json-...@googlegroups.com
We should probably have a set of such example schemas for existing formats somewhere on the website.

Geraint (David)

unread,
Feb 3, 2013, 9:25:37 AM2/3/13
to json-...@googlegroups.com
Ah - I see you made the same suggestion on the GitHub group. :)

David....@sas.com

unread,
Sep 12, 2013, 11:32:09 AM9/12/13
to json-...@googlegroups.com
Francis;

https://github.com/fge/json-schema-validator/blob/master/src/main/resources/json-patch.json  returns a 404 - does this JSON-patch schema exist somewhere else now? I cloned the repo and found no *patch*.json files.

David Biesack

unread,
Sep 12, 2013, 11:41:07 AM9/12/13
to json-...@googlegroups.com

Francis Galiegue

unread,
Sep 24, 2013, 11:56:29 AM9/24/13
to json-...@googlegroups.com
On Thu, Sep 12, 2013 at 5:32 PM, <David....@sas.com> wrote:
> Francis;
>
> https://github.com/fge/json-schema-validator/blob/master/src/main/resources/json-patch.json
> returns a 404 - does this JSON-patch schema exist somewhere else now? I
> cloned the repo and found no *patch*.json files.
>

That would be:

https://github.com/fge/sample-json-schemas/raw/master/json-patch/json-patch.json

Strange, I though I had mentioned the move quite some time ago...

--
Francis Galiegue, fgal...@gmail.com
JSON Schema in Java: http://json-schema-validator.herokuapp.com

shate...@gmail.com

unread,
Apr 2, 2015, 9:56:46 AM4/2/15
to json-...@googlegroups.com

Hi ,
   I am new to Json stuff i.e. JSON PATCH.
I have scenario where I need to figure out between two version of Json files of same object, for that I am using json-patch-master.
But unfortunately the patch generated interpreting it differently i.e. the order differently hence getting unexpected/invalid results. 
Could anyone help me how to preserve the order while generating Json Patch ?

Here is the actual example.

Original Json file :

[ {
  "name" : "name1",
  "roolNo" : "1"
}, {
  "name" : "name2",
  "roolNo" : "2"
}, {
  "name" : "name3",
  "roolNo" : "3"
}, {
  "name" : "name4",
  "roolNo" : "4"
} ]


Modified/New Json file:  i.e. removed 2nd node of original file.

[ {
  "name" : "name1",
  "roolNo" : "1"
}, {
  "name" : "name3",
  "roolNo" : "3"
}, {
  "name" : "name4",
  "roolNo" : "4"
} ]

Patch/Diff Generated :

[ {"op":"remove","path":"/3"},
{"op":"replace","path":"/1/name","value":"name3"},
{"op":"replace","path":"/1/roolNo","value":"3"},
{"op":"replace","path":"/2/name","value":"name4"},
{"op":"replace","path":"/2/roolNo","value":"4"}]

Very time I generate Diff/Patch it is giving different path/diff results.
And moreover the interpretation is different i.e. order is not preserving.

Is there any way to get expected results i.e. [ {"op":"remove","path":"/1"} ] , in other words generated a patch/diff based some order so will get what is expected. ?
How to handle this kind of scenario ?

Please help me.

Thank you so much.
~Shyam

Francis Galiegue

unread,
Apr 2, 2015, 10:09:21 AM4/2/15
to json-...@googlegroups.com
Hello,

This isn't really the mailing list to ask for this. Note that the
generated patch is ultimately correct.

Also, I know that _I_ have a JSON Patch implementation which is able
to generate diffs, but there may be others, so which one are you
referring to? You should open an issue on the issue system of that
particular implementation instead.


Regards,
--
Francis Galiegue, fgal...@gmail.com, https://github.com/fge
Parsers in pure Java: https://github.com/fge/grappa

sha p

unread,
Apr 2, 2015, 8:23:20 PM4/2/15
to json-...@googlegroups.com
Sorry sir,
   As you are expert in json I thought you could give some clue.
Unfortunately json-patch group not letting me send query...hence I posted here.

Anyhow sorry.

Thank you.
~Shyam


--
You received this message because you are subscribed to a topic in the Google Groups "JSON Schema" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/json-schema/p2VJ9B9c3MA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages