Package org.cdk8s

Class 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'));
     
    • Nested Class Summary

      • Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject

        software.amazon.jsii.JsiiObject.InitializationMode
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JsonPatch​(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)  
      protected JsonPatch​(software.amazon.jsii.JsiiObjectRef objRef)  
    • Constructor Detail

      • JsonPatch

        protected JsonPatch​(software.amazon.jsii.JsiiObjectRef objRef)
      • JsonPatch

        protected JsonPatch​(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • 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.