Class JsonPatch
- java.lang.Object
-
- software.amazon.jsii.JsiiObject
-
- io.github.cdklabs.projen.JsonPatch
-
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.96.0 (build 921e240)", date="2024-03-28T21:16:42.771Z") @Stability(Experimental) public class JsonPatch extends software.amazon.jsii.JsiiObject
(experimental) Utility for applying RFC-6902 JSON-Patch to a document.Use the the
JsonPatch.apply(doc, ...ops)function to apply a set of operations to a JSON document and return the result.Operations can be created using the factory methods
JsonPatch.add(),JsonPatch.remove(), etc.Example:
const output = JsonPatch.apply(input, JsonPatch.replace('/world/hi/there', 'goodbye'), JsonPatch.add('/world/foo/', 'boom'), JsonPatch.remove('/hello'));
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JsonPatchadd(String path, Object value)(experimental) Adds a value to an object or inserts it into an array.static Objectapply(Object document, @NotNull JsonPatch... ops)(experimental) Applies a set of JSON-Patch (RFC-6902) operations todocumentand returns the result.static JsonPatchcopy(String from, String path)(experimental) Copies a value from one location to another within the JSON document.static StringescapePath(String path)(experimental) Escapes a json pointer path.static JsonPatchmove(String from, String path)(experimental) Moves a value from one location to the other.static JsonPatchremove(String path)(experimental) Removes a value from an object or array.static JsonPatchreplace(String path, Object value)(experimental) Replaces a value.static JsonPatchtest(String path, Object value)(experimental) Tests that the specified value is set in the document.static JsonPatchtest(String path, Object value, TestFailureBehavior failureBehavior)(experimental) Tests that the specified value is set in the document.-
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
-
-
-
-
Method Detail
-
add
@Stability(Experimental) @NotNull public static JsonPatch add(@NotNull String path, @NotNull Object value)
(experimental) Adds a value to an object or inserts it into an array.In the case of an array, the value is inserted before the given index. The - character can be used instead of an index to insert at the end of an array.
Example:
JsonPatch.add('/biscuits/1', { "name": "Ginger Nut" })- Parameters:
path- This parameter is required.value- This parameter is required.
-
apply
@Stability(Experimental) @NotNull public static Object apply(@NotNull Object document, @NotNull @NotNull JsonPatch... ops)
(experimental) Applies a set of JSON-Patch (RFC-6902) operations todocumentand returns the result.- Parameters:
document- The document to patch. This parameter is required.ops- The operations to apply. This parameter is required.- Returns:
- The result document
-
copy
@Stability(Experimental) @NotNull public static JsonPatch copy(@NotNull String from, @NotNull String path)
(experimental) Copies a value from one location to another within the JSON document.Both from and path are JSON Pointers.
Example:
JsonPatch.copy('/biscuits/0', '/best_biscuit')- Parameters:
from- This parameter is required.path- This parameter is required.
-
escapePath
@Stability(Experimental) @NotNull public static String escapePath(@NotNull String path)
(experimental) Escapes a json pointer path.- Parameters:
path- The raw pointer. This parameter is required.- Returns:
- the Escaped path
-
move
@Stability(Experimental) @NotNull public static JsonPatch move(@NotNull String from, @NotNull String path)
(experimental) Moves a value from one location to the other.Both from and path are JSON Pointers.
Example:
JsonPatch.move('/biscuits', '/cookies')- Parameters:
from- This parameter is required.path- This parameter is required.
-
remove
@Stability(Experimental) @NotNull public static JsonPatch remove(@NotNull String path)
(experimental) Removes a value from an object or array.Example:
JsonPatch.remove('/biscuits/0')- Parameters:
path- This parameter is required.
-
replace
@Stability(Experimental) @NotNull public static JsonPatch replace(@NotNull String path, @NotNull Object value)
(experimental) Replaces a value.Equivalent to a “remove” followed by an “add”.
Example:
JsonPatch.replace('/biscuits/0/name', 'Chocolate Digestive')- Parameters:
path- This parameter is required.value- This parameter is required.
-
test
@Stability(Experimental) @NotNull public static JsonPatch test(@NotNull String path, @NotNull Object value, @Nullable TestFailureBehavior failureBehavior)
(experimental) Tests that the specified value is set in the document.If the test fails, then the patch as a whole should not apply.
Example:
JsonPatch.test('/best_biscuit/name', 'Choco Leibniz')- Parameters:
path- This parameter is required.value- This parameter is required.failureBehavior-
-
test
@Stability(Experimental) @NotNull public static JsonPatch test(@NotNull String path, @NotNull Object value)
(experimental) Tests that the specified value is set in the document.If the test fails, then the patch as a whole should not apply.
Example:
JsonPatch.test('/best_biscuit/name', 'Choco Leibniz')- Parameters:
path- This parameter is required.value- This parameter is required.
-
-