2

I have a Json document that I want to allow user to add to and edit using JsonPath.

This answer works brilliantly when the document contains the path represented as JsonPath, but does not work when part (or all) of the JsonPath doesn't exist in the document I'm editing.

For example, I want to set: $.test.configuration to some Json value {...} in a document {} so that the final result looks like this.

{
   "test":{
      "configuration": {...}
   }
}

I've also found a C# JsonPath parser, but it doesn't give me any ideas on how to use it and create the path specified.

Your help is appreciated, thanks in advance!

EDIT: Based on the answer by @cecilphilip, I found JsonDiffPatch which is perfect for my needs!

Community
  • 1
  • 1
Ani
  • 10,826
  • 3
  • 27
  • 46
  • from my understanding, JSON Path is really for querying, which might explain why you have issues with non existent nodes. Have you considered taking a look at JSON Patch? http://jsonpatch.com/ – cecilphillip Mar 21 '16 at 02:23
  • That's what I was looking for. I found a good .NET implementation of JSON patch (https://github.com/mcintyre321/JsonDiffPatch) compatible with Json.NET. Please make this an answer and I'll accept. Thanks! – Ani Mar 21 '16 at 02:46

1 Answers1

1

JSON Path is really for querying, which might explain why you have issues with non existent nodes. Have you considered taking a look at JSON Patch? jsonpatch.com. This is probably what you need instead.

cecilphillip
  • 11,446
  • 4
  • 36
  • 40