Subject: [apps-discuss] Updated JSON Predicates

From: James M Snell <[email-masked]>
Date: Mon, 7 Jan 2013 12:55:07 -0800

I have posted an update to the JSON Predicates document. Again, as I've
mentioned before, this draft is largely experimental in nature at this
point and is intended to provide additional predicate operations to JSON
Patch. It is still very much a work in progress and is far from completion.
Nothing in the doc should be set in stone, particularly the new stuff I
just added. Comments and feedback are welcome... even if only to tell me
how bad of an idea the new stuff may be ;-)

http://www.ietf.org/id/draft-snell-json-test-05.txt

The main changes are:

1. Dedicate mime media type for JSON Patch documents that include JSON
Predicates

2. New conditional operation properties that can be used to alter the
processing of a JSON Patch operation. For instance:

  {
    "op": "add",
    "path": "/a/b/-",
    "value": 1,
    "if": {
      "op": "and",
      "path": "/a/b",
      "apply": [
        {"op":"defined"},
        {"op":"type", "value": "array"}
      ]
    }
  }

In this case, the value 1 will be added to "/a/b/-" only if "/a/b" exists
and is an array. If that condition is not met, the operation is simply
skipped over and processing of the patch document continues without
reporting an error.

I fully understand why this type of change would be controversial. So why
would we do this? Consider the following example:

     [
       {
         "op": "add",
         "path": "/a/b",
         "value": [],
         "unless": {
           "op": "type",
           "value": "array"
         }
       },
       {
         "op": "add",
         "path": "/a/b/-",
         "value": "ABC"
       }
     ]

Here, the Patch document will ensure that the path "/a/b" exists and is an
array prior to applying the secondary and. If "/a/b" exists and is not an
array, it's value is overridden and changed to an array. If "/a/b" doesn't
exist, it's added. If "/a/b" does exist and is already an array, processing
just skips over the first "add" and moves on to the second one.

Yes, there are other ways of doing this. I added this to the document in
order to get it on the table for discussion. I think it would be useful and
have examples, but I'm not opposed to pulling it back out.

Feedback and comments are more than welcome, as always.

- James