Skip to content

Commit

Permalink
Add json_merge documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vladpaiu committed Jan 10, 2025
1 parent a910f92 commit aaebd05
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
27 changes: 27 additions & 0 deletions modules/json/README
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
30 changes: 27 additions & 3 deletions modules/json/doc/json_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,36 @@ xlog("\nTest link :\n$json(stub)\n$json(b)\n\n");

</section>


</section>
<section id="func_json_merge" xreflabel="json_merge()">
<title>
<function moreinfo="none">
json_merge(main_json_var,patch_json_var,output_var))
</function>
</title>
<para>
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
</para>


<example>
<title>Using json_merge </title>
<programlisting format="linespecific">
...

$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"}
</programlisting>
</example>
</section>
</section>
</chapter>

0 comments on commit aaebd05

Please sign in to comment.