1====== JSON Data Usage Demo ======
2
3
4===== Example JSON data =====
5<code javascript>
6<json path=person> {
7    "firstName": "James",
8    "lastName": "Smith",
9    "email": "james.smith@example.com|Salesman email address",
10    "age": 30,
11    "motorcycles": false,
12    "cars": [
13        { "name":"Ford", "url": "https://ford.com", "models": [ "Fiesta", "Focus", "Mustang" ] },
14        { "name":"BMW", "url": "https://bmw.com", "models": [ "320", "X3", "X5" ] },
15        { "name":"Fiat", "url": "https://fiat.com", "models": [ "500", "Panda" ] }
16    ]
17}</json>
18</code>
19<json path=person> {
20    "firstName": "James",
21    "lastName": "Smith",
22    "email": "james.smith@example.com|Salesman email address",
23    "age": 30,
24    "motorcycles": false,
25    "cars": [
26        { "name":"Ford", "url": "https://ford.com", "models": [ "Fiesta", "Focus", "Mustang" ] },
27        { "name":"BMW", "url": "https://bmw.com", "models": [ "320", "X3", "X5" ] },
28        { "name":"Fiat", "url": "https://fiat.com", "models": [ "500", "Panda" ] }
29    ]
30}</json>
31
32
33===== Extract text =====
34Basic extractor syntax: ''%%%$ ... %%%''
35
36<code>
37%$person.firstName% %$person.lastName% sells cars.
38</code>
39%$person.firstName% %$person.lastName% sells cars.
40
41<code>
42person.middleName: **%$person.middleName%**. person.cars: **%$person.cars%**. person.cars.1.models: **%$person.cars.1.models%**.
43</code>
44person.middleName: **%$person.middleName%**. person.cars: **%$person.cars%**. person.cars.1.models: **%$person.cars.1.models%**.
45
46
47===== Filter =====
48Basic syntax: ''%%%$ ... ( ... )%%%''
49
50Variable will be displayed, if filter evaluates to true.
51
52<code>
53This person is older than 40: %$person.firstName(person.age>40)%. This person is younger than 40: %$person.firstName(person.age<=40)%.
54</code>
55This person is older than 40: %$person.firstName(person.age>40)%. This person is younger than 40: %$person.firstName(person.age<=40)%.
56
57
58===== Format =====
59Basic syntax: ''%%%$ ... # ... #%%%''
60
61Variable may be rendered in one of the following formats: code, header, link, email, media, rss or ejs.
62
63<code>
64%$person.cars.1.models #code#%
65</code>
66%$person.cars.1.models #code#%
67
68<code>
69%$person.email #email#%
70</code>
71Email: %$person.email #email#%
72
73To use [[https://ejs.co/|Embedded JavaScript templating]] first enable it in the configuration settings.
74<code>
75%$person.firstName #ejs?<$=d.toUpperCase()$>#%
76</code>
77
78In upper case: %$person.firstName #ejs?<$=d.toUpperCase()$>#%
79
80
81===== Extract list =====
82==== List of all properties ====
83Syntax: ''%%%$ ... {}%%%''
84
85Empty curly brackets lists all properties of the variable.
86<code>
87%$person{}%
88</code>
89%$person{}%
90
91==== Partial list ====
92Syntax: ''%%%$ ... { ... }%%%''
93
94Curly brackets may contain pairs with header description linked to path.
95<code>
96%$person{"First name":firstName, "Age":age, "Main car":cars.0.name, "Not existing":middleName}%
97</code>
98%$person{"First name":firstName, "Age":age, "Main car":cars.0.name, "Not existing":middleName}%
99
100==== Format specific member ====
101Syntax: ''%%%$ ... { ... } # ... #%%%''
102
103Format must contain pairs with header description linked to format.
104<code>
105%$person{"First name":firstName, "Email address":email, "Main car":cars.0.name} #"Email address":email#%
106</code>
107%$person{"First name":firstName, "Email address":email, "Main car":cars.0.name} #"Email address":email#%
108
109
110===== Extract table =====
111==== Simple table ====
112Syntax: ''%%%$ ... []%%%''
113
114If variable is simple double array, it can be displayed, if square brackets are added after the variable. Table has no header. If variable is not well formed, table may show unpredictable results.
115<code>
116%$person.cars[]%
117</code>
118%$person.cars[]%
119
120To generate table header automatically add empty curly brackets.
121<code>
122%$person.cars[]{}%
123</code>
124%$person.cars[]{}%
125
126==== Table with specified header ====
127Syntax: ''%%%$ ... []{ ... }%%%''
128
129Curly brackets contain pairs with header name and path for each column.
130<code>
131%$person.cars[]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}%
132</code>
133%$person.cars[]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}%
134
135==== Table with row filter ====
136Syntax: ''%%%$ ... [( ... )]{ ... }%%%''
137
138Filter rules may be added inside brackets inside square brackets. Each row will be checked against filter.
139
140<code>
141%$person.cars[(name > b and name <= fiat)]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}%
142</code>
143%$person.cars[(name > b and name <= fiat)]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}%
144
145==== Table with column format ====
146Syntax: ''%%%$ ... []{ ... } # ... #%%%''
147
148Format must contain pairs with header description linked to format.
149
150<code>
151%$person.cars[]{"Name":name, "Webpage":url, "Models":models, "Number of models":models} #Webpage:link, "Number of models":ejs?<$=d.length$>#%
152</code>
153%$person.cars[]{"Name":name, "Webpage":url, "Models":models, "Number of models":models} #Webpage:link, "Number of models":ejs?<$=d.length$>#%
154
155
156===== Show or Hide sections =====
157Show contents only, if it matches [[json_plugin#filters|filter]] inside brackets. Syntax: ''%%%$-start ( ... )% ... %$end%%%''
158<code>
159%$-start (person.cars)%
160==== Section about Cars ====
161This section should **be visible**.
162%$end%
163</code>
164
165%$-start (person.cars)%
166==== Section about Cars ====
167
168This section should **be visible**.
169%$end%
170
171
172<code>
173%$-start (person.motorcycles)%
174==== Section about Motorcycles ====
175This section should not be visible.
176
177Not even in TOC.
178%$end%
179</code>
180
181%$-start (person.motorcycles)%
182==== Section about Motorcycles ====
183This section should not be visible.
184
185Not even in TOC.
186%$end%
187
188
189===== Show or Hide inline text =====
190Mind extra ''i'' in ''%%%$-start%%''**''i''**'' ( ... )% ... %%%$%%end%'' for inline text.
191<code>
192He sells
193%$-starti (person.cars)%**Cars**%$end%
194%$-starti (person.cars and person.motorcycles)% and %$end%
195%$-starti (person.motorcycles)%**Motorcycles**%$end%.
196</code>
197He sells
198%$-starti (person.cars)%**Cars**%$end%
199%$-starti (person.cars and person.motorcycles)% and %$end%
200%$-starti (person.motorcycles)%**Motorcycles**%$end%.
201