@@ -22,6 +22,7 @@ public class Json {
2222 private static final String JSON_PREFIX = "JSON." ;
2323 public static final String JSON_SET = JSON_PREFIX + "SET" ;
2424 public static final String JSON_GET = JSON_PREFIX + "GET" ;
25+ private static final String JSON_ARRAPPEND = JSON_PREFIX + "ARRAPPEND" ;
2526 private static final String JSON_ARRINSERT = JSON_PREFIX + "ARRINSERT" ;
2627 private static final String JSON_ARRLEN = JSON_PREFIX + "ARRLEN" ;
2728
@@ -390,6 +391,86 @@ public static CompletableFuture<GlideString> get(
390391 new ArgsBuilder ().add (gs (JSON_GET )).add (key ).add (options .toArgs ()).add (paths ).toArray ());
391392 }
392393
394+ /**
395+ * Appends one or more <code>values</code> to the JSON array at the specified <code>path</code>
396+ * within the JSON document stored at <code>key</code>.
397+ *
398+ * @param client The client to execute the command.
399+ * @param key The <code>key</code> of the JSON document.
400+ * @param path Represents the <code>path</code> within the JSON document where the <code>values
401+ * </code> will be appended.
402+ * @param values The <code>values</code> to append to the JSON array at the specified <code>path
403+ * </code>.
404+ * @return
405+ * <ul>
406+ * <li>For JSONPath (<code>path</code> starts with <code>$</code>):<br>
407+ * Returns a list of integers for every possible path, indicating the new length of the
408+ * new array after appending <code>values</code>, or <code>null</code> for JSON values
409+ * matching the path that are not an array. If <code>path</code> does not exist, an
410+ * empty array will be returned.
411+ * <li>For legacy path (<code>path</code> doesn't start with <code>$</code>):<br>
412+ * Returns the length of the new array after appending <code>values</code> to the array
413+ * at <code>path</code>. If multiple paths are matched, returns the last updated array.
414+ * If the JSON value at <code>path</code> is not a array or if <code>path</code> doesn't
415+ * exist, an error is raised. If <code>key</code> doesn't exist, an error is raised.
416+ * @example
417+ * <pre>{@code
418+ * Json.set(client, "doc", "$", "{\"a\": 1, \"b\": [\"one\", \"two\"]}").get();
419+ * var res = Json.arrappend(client, "doc", "$.b", new String[] {"\"three\""}).get();
420+ * assert Arrays.equals((Object[]) res, new int[] {3}); // New length of the array after appending
421+ * res = Json.arrappend(client, "doc", ".b", new String[] {"\"four\""}).get();
422+ * assert res.equals(4); // New length of the array after appending
423+ * }</pre>
424+ */
425+ public static CompletableFuture <Object > arrappend (
426+ @ NonNull BaseClient client ,
427+ @ NonNull String key ,
428+ @ NonNull String path ,
429+ @ NonNull String [] values ) {
430+ return executeCommand (
431+ client , concatenateArrays (new String [] {JSON_ARRAPPEND , key , path }, values ));
432+ }
433+
434+ /**
435+ * Appends one or more <code>values</code> to the JSON array at the specified <code>path</code>
436+ * within the JSON document stored at <code>key</code>.
437+ *
438+ * @param client The client to execute the command.
439+ * @param key The <code>key</code> of the JSON document.
440+ * @param path Represents the <code>path</code> within the JSON document where the <code>values
441+ * </code> will be appended.
442+ * @param values The <code>values</code> to append to the JSON array at the specified <code>path
443+ * </code>.
444+ * @return
445+ * <ul>
446+ * <li>For JSONPath (<code>path</code> starts with <code>$</code>):<br>
447+ * Returns a list of integers for every possible path, indicating the new length of the
448+ * new array after appending <code>values</code>, or <code>null</code> for JSON values
449+ * matching the path that are not an array. If <code>path</code> does not exist, an
450+ * empty array will be returned.
451+ * <li>For legacy path (<code>path</code> doesn't start with <code>$</code>):<br>
452+ * Returns the length of the new array after appending <code>values</code> to the array
453+ * at <code>path</code>. If multiple paths are matched, returns the last updated array.
454+ * If the JSON value at <code>path</code> is not a array or if <code>path</code> doesn't
455+ * exist, an error is raised. If <code>key</code> doesn't exist, an error is raised.
456+ * @example
457+ * <pre>{@code
458+ * Json.set(client, "doc", "$", "{\"a\": 1, \"b\": [\"one\", \"two\"]}").get();
459+ * var res = Json.arrappend(client, gs("doc"), gs("$.b"), new GlideString[] {gs("\"three\"")}).get();
460+ * assert Arrays.equals((Object[]) res, new int[] {3}); // New length of the array after appending
461+ * res = Json.arrappend(client, gs("doc"), gs(".b"), new GlideString[] {gs("\"four\"")}).get();
462+ * assert res.equals(4); // New length of the array after appending
463+ * }</pre>
464+ */
465+ public static CompletableFuture <Object > arrappend (
466+ @ NonNull BaseClient client ,
467+ @ NonNull GlideString key ,
468+ @ NonNull GlideString path ,
469+ @ NonNull GlideString [] values ) {
470+ return executeCommand (
471+ client , new ArgsBuilder ().add (gs (JSON_ARRAPPEND )).add (key ).add (path ).add (values ).toArray ());
472+ }
473+
393474 /**
394475 * Inserts one or more values into the array at the specified <code>path</code> within the JSON
395476 * document stored at <code>key</code>, before the given <code>index</code>.
0 commit comments