Package org.cdk8s
Class JsonPatch
- java.lang.Object
-
- software.amazon.jsii.JsiiObject
-
- org.cdk8s.JsonPatch
-
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.81.0 (build 80988b0)", date="2023-05-15T18:42:27.037Z") @Stability(Stable) public class JsonPatch extends software.amazon.jsii.JsiiObject
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 JsonPatch
add(String path, Object value)
Adds a value to an object or inserts it into an array.static Object
apply(Object document, @NotNull JsonPatch... ops)
Applies a set of JSON-Patch (RFC-6902) operations to `document` and returns the result.static JsonPatch
copy(String from, String path)
Copies a value from one location to another within the JSON document.static JsonPatch
move(String from, String path)
Moves a value from one location to the other.static JsonPatch
remove(String path)
Removes a value from an object or array.static JsonPatch
replace(String path, Object value)
Replaces a value.static JsonPatch
test(String path, Object value)
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(Stable) @NotNull public static JsonPatch add(@NotNull String path, @NotNull Object value)
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(Stable) @NotNull public static Object apply(@NotNull Object document, @NotNull @NotNull JsonPatch... ops)
Applies a set of JSON-Patch (RFC-6902) operations to `document` and 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(Stable) @NotNull public static JsonPatch copy(@NotNull String from, @NotNull String path)
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.
-
move
@Stability(Stable) @NotNull public static JsonPatch move(@NotNull String from, @NotNull String path)
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(Stable) @NotNull public static JsonPatch remove(@NotNull String path)
Removes a value from an object or array.Example:
JsonPatch.remove('/biscuits/0')
- Parameters:
path
- This parameter is required.
-
replace
@Stability(Stable) @NotNull public static JsonPatch replace(@NotNull String path, @NotNull Object value)
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(Stable) @NotNull public static JsonPatch test(@NotNull String path, @NotNull Object value)
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.
-
-