1#+begin_src cfengine3
2bundle common globals
3{
4  vars:
5      "example_data" data => '{ "msg": "Hello from $(this.bundle)" }';
6}
7bundle agent example_storejson
8# @brief Example showing storejson
9{
10  vars:
11      "example_data" data => '{ "msg": "Hello from $(this.bundle)" }';
12
13      # Using storejson with data from remote bundle
14
15      # "json_string_zero" -> { "CFEngine 3.16.0"}
16      #    string => storejson( globals.example_data )
17      #    comment => "Unquoted with . (dot) present will cause the parser to error";
18
19      "json_string_one"   string => storejson( @(globals.example_data) );
20      "json_string_two"   string => storejson( "globals.example_data" );
21
22      # Using storejson with data from this bundle
23      "json_string_three" string => storejson( @(example_storejson.example_data) );
24      "json_string_four"  string => storejson( "example_storejson.example_data");
25      "json_string_five"  string => storejson( example_data );
26      "json_string_six"   string => storejson( "$(this.bundle).example_data");
27      "json_string_seven" string => storejson( @(example_data) );
28
29  reports:
30      "json_string_one and json_string_two are identical:$(const.n)$(json_string_one)"
31        if => strcmp( $(json_string_one), $(json_string_two) );
32
33      "json_string_{one,two,three,four,five,six,seven} are identical:$(const.n)$(json_string_three)"
34        if => and(
35                   strcmp( $(json_string_three), $(json_string_four) ),
36                   strcmp( $(json_string_four), $(json_string_five) ),
37                   strcmp( $(json_string_five), $(json_string_six) ),
38                   strcmp( $(json_string_six), $(json_string_seven) )
39        );
40}
41
42bundle agent __main__
43{
44  methods: "example_storejson";
45}
46###############################################################################
47#+end_src
48#+begin_src example_output
49#@ ```
50#@ R: json_string_one and json_string_two are identical:
51#@ {
52#@       "msg": "Hello from globals"
53#@ }
54#@ R: json_string_{one,two,three,four,five,six,seven} are identical:
55#@ {
56#@       "msg": "Hello from example_storejson"
57#@ }
58#@ ```
59#+end_src
60