Home Applications objectscript-json-patch

objectscript-json-patch

This application is not supported by InterSystems Corporation. Please be notified that you use it at your own risk.
4.5
2 reviews
0
Awards
144
Views
15
IPM installs
3
2
Details
Releases
Reviews
Issues
Pull requests
Articles
An implementation of JSON-Path in ObjectScript.

What's new in this version

update module.xml description

objectscript-json-patch

alt text

An implementation of JSON-Patch in ObjectScript.

Why you should use JSON-Patch

JSON-Patch (RFC6902) is a standard format that allows you to update a JSON document by sending the changes rather than the whole document.
JSON Patch plays well with the HTTP PATCH verb (method) and REST style programming.

Install

With zpm :

USER>zpm
zpm:USER>install objectscript-json-patch

How-To use it

Use it with this call :

Do ##class(Grongier.JSON.Utils).Patch(tDoc,tPatch)

Where :

  • tDoc is a %DynamicObject (JSON)
  • tPatch is a %DynamicArray of the patches (the JSON Patch).

The result will be tDoc patched.

Example

Set tDoc = {
            "foo": {
                    "bar": "baz",
                    "waldo": "fred"
                  },
            "qux": {
                    "corge": "grault"
            }

Set tPatch = [
{
"op": "move",
"from": "/foo/waldo",
"path": "/qux/thud"
}
]

Do ##class(Grongier.JSON.Utils).Patch(tDoc,tPatch)

zw tDoc.%ToJSON()

Result

  {
    "foo": {
              "bar": "baz"
           },
    "qux": {
              "corge": "grault",
              "thud": "fred"
          }
   }

Test this module

Natively from git :

do ##class(%UnitTest.Manager).DebugRunTestCase("","Test.Grongier.JSON.Utils",,)

With zpm :

USER>zpm
zpm:USER>module-action objectscript-json-patch test

Special thanks

  • Michel Liberado for the idea
Read more
Made with
Install
zpm install objectscript-json-patch download archive
Version
1.0.108 Dec, 2020
Category
Developer Environment
Works with
InterSystems IRISInterSystems IRIS for Health
First published
28 Apr, 2020
Last checked by moderator
27 Jun, 2023Works