User Tools

Site Tools


json:json_usage_demo

JSON Data Usage Demo

Example JSON data

<json path=person> {
    "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" ] }
    ]
}</json>
  • element: json, path: person, inline data

Extract text

Basic extractor syntax: %$ ... %

%$person.firstName% %$person.lastName% sells cars.

James Smith sells cars.

person.middleName: **%$person.middleName%**. person.cars: **%$person.cars%**. person.cars.1.models: **%$person.cars.1.models%**.

person.middleName: (null). person.cars: (array). person.cars.1.models: 320, X3, X5.

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: . This person is younger than 40: James.

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#%

[
    "320",
    "X3",
    "X5"
]

%$person.email #email#%

Email: Salesman email address

To use Embedded JavaScript templating first enable it in the configuration settings.

%$person.firstName #ejs?<$=d.toUpperCase()$>#%

In upper case: "James"<%=d.toUpperCase()%>

Extract list

List of all properties

Syntax: %$ ... {}%

Empty curly brackets lists all properties of the variable.

%$person{}%

firstNameJames
lastNameSmith
emailjames.smith@example.com|Salesman email address
age30
motorcycles
cars(array)

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}%

First nameJames
Age30
Main carFord
Not existing(null)

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#%

First nameJames
Email addressSalesman email address
Main carFord

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[]%

Fordhttps://ford.comFiesta, Focus, Mustang
BMWhttps://bmw.com320, X3, X5
Fiathttps://fiat.com500, Panda

To generate table header automatically add empty curly brackets.

%$person.cars[]{}%

nameurlmodels
Fordhttps://ford.comFiesta, Focus, Mustang
BMWhttps://bmw.com320, X3, X5
Fiathttps://fiat.com500, Panda

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}%

NameModel 1Model 2Model 3
FordFiestaFocusMustang
BMW320X3X5
Fiat500Panda(null)

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}%

NameModel 1Model 2Model 3
BMW320X3X5
Fiat500Panda(null)

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$>#%

NameWebpageModelsNumber of models
Fordhttps://ford.comFiesta, Focus, Mustang["Fiesta","Focus","Mustang"]<%=d.length%>
BMWhttps://bmw.com320, X3, X5["320","X3","X5"]<%=d.length%>
Fiathttps://fiat.com500, Panda["500","Panda"]<%=d.length%>

Show or Hide sections

Show contents only, if it matches filter inside brackets. Syntax: %$-start ( ... )% ... %$end%

%$-start (person.cars)%
==== Section about Cars ====
This section should **be visible**.
%$end%

Section about Cars

This section should be visible.

%$-start (person.motorcycles)%
==== Section about Motorcycles ====
This section should not be visible.

Not even in TOC.
%$end%

TOC

Show or Hide inline text

Mind extra i in %$-starti ( … )% … %$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 Cars Motorcycles.

json/json_usage_demo.txt · Last modified: 2023/10/26 18:47 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki