From aaebd052319b6962f116c97eb671d22b70f2137f Mon Sep 17 00:00:00 2001 From: Vlad Paiu Date: Fri, 10 Jan 2025 13:17:31 +0200 Subject: [PATCH] Add json_merge documentation --- modules/json/README | 27 +++++++++++++++++++++++++++ modules/json/doc/json_admin.xml | 30 +++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/modules/json/README b/modules/json/README index 29cd6ec2f1..0f0bc5499b 100644 --- a/modules/json/README +++ b/modules/json/README @@ -24,6 +24,9 @@ JSON Module 1.5. Exported Functions 1.5.1. json_link($json(dest_id), $json(source_id)) + 1.5.2. + json_merge(main_json_var,patch_json_var,output + _var)) 2. Contributors @@ -57,6 +60,7 @@ JSON Module 1.12. Adding a json to another json 1.13. Creating a reference 1.14. [LOGICAL ERROR] Creating a circular reference + 1.15. Using json_merge Chapter 1. Admin Guide @@ -406,6 +410,29 @@ xlog("\nTest link :\n$json(stub)\n$json(b)\n\n"); ... +1.5.2. json_merge(main_json_var,patch_json_var,output_var)) + + The function can be used to patch merge patch_json_var into + main_json_var and the output will be populated into the + output_var + + Example 1.15. Using json_merge +... + +$json(val1) := "{}"; +$json(val1/test1) = "test_val1"; +$json(val1/common_val) = "val_from1"; + +$json(val2) := "{}"; +$json(val2/test2) = "test_val2"; +$json(val1/common_val) = "val_from2"; + +json_merge($json(val1),$json(val2),$var(merged_json)); +xlog("we merged and got $var(merged_json) \n"); +# will print : +# we merged and got {"test1":"test_val1","common_val":"val_from2","test2 +":"test_val2"} + Chapter 2. Contributors 2.1. By Commit Statistics diff --git a/modules/json/doc/json_admin.xml b/modules/json/doc/json_admin.xml index ea4b2b7d81..b73d715943 100644 --- a/modules/json/doc/json_admin.xml +++ b/modules/json/doc/json_admin.xml @@ -539,12 +539,36 @@ xlog("\nTest link :\n$json(stub)\n$json(b)\n\n"); - - +
+ + <function moreinfo="none"> + json_merge(main_json_var,patch_json_var,output_var)) + </function> + + + The function can be used to patch merge patch_json_var into main_json_var and the output will be populated into the output_var + - + + Using json_merge + +... +$json(val1) := "{}"; +$json(val1/test1) = "test_val1"; +$json(val1/common_val) = "val_from1"; +$json(val2) := "{}"; +$json(val2/test2) = "test_val2"; +$json(val1/common_val) = "val_from2"; +json_merge($json(val1),$json(val2),$var(merged_json)); +xlog("we merged and got $var(merged_json) \n"); +# will print : +# we merged and got {"test1":"test_val1","common_val":"val_from2","test2":"test_val2"} + + +
+