====== JSON Data Usage Demo ====== ===== Example JSON data ===== { "firstName": "James", "lastName": "Smith", "email": "james.smith@example.com|Salesman email address", "age": 30, "motorcycles": false, "cars": [ { "name":"Ford", "url": "https://ford.com", "models": [ "Fiesta", "Focus", "Mustang" ] }, { "name":"BMW", "url": "https://bmw.com", "models": [ "320", "X3", "X5" ] }, { "name":"Fiat", "url": "https://fiat.com", "models": [ "500", "Panda" ] } ] } { "firstName": "James", "lastName": "Smith", "email": "james.smith@example.com|Salesman email address", "age": 30, "motorcycles": false, "cars": [ { "name":"Ford", "url": "https://ford.com", "models": [ "Fiesta", "Focus", "Mustang" ] }, { "name":"BMW", "url": "https://bmw.com", "models": [ "320", "X3", "X5" ] }, { "name":"Fiat", "url": "https://fiat.com", "models": [ "500", "Panda" ] } ] } ===== Extract text ===== Basic extractor syntax: ''%%%$ ... %%%'' %$person.firstName% %$person.lastName% sells cars. %$person.firstName% %$person.lastName% sells cars. person.middleName: **%$person.middleName%**. person.cars: **%$person.cars%**. person.cars.1.models: **%$person.cars.1.models%**. person.middleName: **%$person.middleName%**. person.cars: **%$person.cars%**. person.cars.1.models: **%$person.cars.1.models%**. ===== Filter ===== Basic syntax: ''%%%$ ... ( ... )%%%'' Variable will be displayed, if filter evaluates to true. This person is older than 40: %$person.firstName(person.age>40)%. This person is younger than 40: %$person.firstName(person.age<=40)%. This person is older than 40: %$person.firstName(person.age>40)%. This person is younger than 40: %$person.firstName(person.age<=40)%. ===== Format ===== Basic syntax: ''%%%$ ... # ... #%%%'' Variable may be rendered in one of the following formats: code, header, link, email, media, rss or ejs. %$person.cars.1.models #code#% %$person.cars.1.models #code#% %$person.email #email#% Email: %$person.email #email#% To use [[https://ejs.co/|Embedded JavaScript templating]] first enable it in the configuration settings. %$person.firstName #ejs?<$=d.toUpperCase()$>#% In upper case: %$person.firstName #ejs?<$=d.toUpperCase()$>#% ===== Extract list ===== ==== List of all properties ==== Syntax: ''%%%$ ... {}%%%'' Empty curly brackets lists all properties of the variable. %$person{}% %$person{}% ==== Partial list ==== Syntax: ''%%%$ ... { ... }%%%'' Curly brackets may contain pairs with header description linked to path. %$person{"First name":firstName, "Age":age, "Main car":cars.0.name, "Not existing":middleName}% %$person{"First name":firstName, "Age":age, "Main car":cars.0.name, "Not existing":middleName}% ==== Format specific member ==== Syntax: ''%%%$ ... { ... } # ... #%%%'' Format must contain pairs with header description linked to format. %$person{"First name":firstName, "Email address":email, "Main car":cars.0.name} #"Email address":email#% %$person{"First name":firstName, "Email address":email, "Main car":cars.0.name} #"Email address":email#% ===== Extract table ===== ==== Simple table ==== Syntax: ''%%%$ ... []%%%'' If 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. %$person.cars[]% %$person.cars[]% To generate table header automatically add empty curly brackets. %$person.cars[]{}% %$person.cars[]{}% ==== Table with specified header ==== Syntax: ''%%%$ ... []{ ... }%%%'' Curly brackets contain pairs with header name and path for each column. %$person.cars[]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}% %$person.cars[]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}% ==== Table with row filter ==== Syntax: ''%%%$ ... [( ... )]{ ... }%%%'' Filter rules may be added inside brackets inside square brackets. Each row will be checked against filter. %$person.cars[(name > b and name <= fiat)]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}% %$person.cars[(name > b and name <= fiat)]{"Name":name, "Model 1":models.0, "Model 2":models.1, "Model 3":models.2}% ==== Table with column format ==== Syntax: ''%%%$ ... []{ ... } # ... #%%%'' Format must contain pairs with header description linked to format. %$person.cars[]{"Name":name, "Webpage":url, "Models":models, "Number of models":models} #Webpage:link, "Number of models":ejs?<$=d.length$>#% %$person.cars[]{"Name":name, "Webpage":url, "Models":models, "Number of models":models} #Webpage:link, "Number of models":ejs?<$=d.length$>#% ===== Show or Hide sections ===== Show contents only, if it matches [[json_plugin#filters|filter]] inside brackets. Syntax: ''%%%$-start ( ... )% ... %$end%%%'' %$-start (person.cars)% ==== Section about Cars ==== This section should **be visible**. %$end% %$-start (person.cars)% ==== Section about Cars ==== This section should **be visible**. %$end% %$-start (person.motorcycles)% ==== Section about Motorcycles ==== This section should not be visible. Not even in TOC. %$end% %$-start (person.motorcycles)% ==== Section about Motorcycles ==== This section should not be visible. Not even in TOC. %$end% ===== Show or Hide inline text ===== Mind extra ''i'' in ''%%%$-start%%''**''i''**'' ( ... )% ... %%%$%%end%'' for inline text. He sells %$-starti (person.cars)%**Cars**%$end% %$-starti (person.cars and person.motorcycles)% and %$end% %$-starti (person.motorcycles)%**Motorcycles**%$end%. He sells %$-starti (person.cars)%**Cars**%$end% %$-starti (person.cars and person.motorcycles)% and %$end% %$-starti (person.motorcycles)%**Motorcycles**%$end%.