Objects

ISL can be used to model all types of objects, in alignment with the JSON format.

Just use the , (comma) as the separator and use " " (quotes) for property names that have special characters:

Simple Objects

$result: {
	property: true,
	"long-field": "yes"
}

Will output:

{
	"property": true,
	"long-field": "yes"
}

Dynamic Property Names

String Interpolation can be used to dynamically generate property names on objects for example from a variable name:

$propName: 'my-custom-property';

$result: {
	property: true,
	`$propName`: "yes"
}

Will output:

{
	"property": true,
	"my-custom-property": "yes"
}

Spread Operator

The ... (spread) operator can be used to deep-copy a complete object or an array into another object/array.

$input: { value1: true, value2: false }

$result: { 
	...$input,	// copy $input inline
	value3: "yey"
}

Will output:

{ 
	"value1": true,
	"value2": false,
	"value3": "yey"
}

Multiple objects can be spread in-place:

$input1: { value1: true, value2: false }
$input2: { value4: true, value5: false }

$result: { 
	...$input1,	
	value3: "yey",
	...$input2
}

Will output:

{ 
	// from input1
	"value1": true,
	"value2": false,
	// inline
	"value3": "yey",
	// from input2
	"value4": true,
	"value5": false
}

Arrays will be copied in-place:

$input: [ 1, 2 ]

$result: [ 
	...$input,	// copy $input inline
	3
]

Will output:

[ 1, 2, 3]

Inline Ifs

You can also create conditional properties using inline if statements or coalesce ?? conditions

$result: {
	useStartDate: if ( 2 > 1 ) true else false,
	useEndDate: if ( 1 > 2 ) true else false,
	// there is no else - so no property is generated at all
	useBothDates: if ( 1 > 2 ) true,
	// use result.data or a default value via coalesce
	value: $result.data ?? 'defaultValue',
}

Will output:

{
	"useStartDate": true,
	"useEndDate": false,
	// No `useBothDates` property is generated as the false result has no value
	"value": "defaultValue"
}

Switch Case

A switch case statement can be embedded inside an object to generate a conditional property

$val: 3;

$result: {
	start: switch( $val )
		1 -> "a";
		2 -> "b";
		3 -> "c";
	endswitch
}

Will output:

{
	"start": "c"
}

Note that the switch case statement also supports conditions ( ==, !=, <=, =>, <, >, contains, in, … ) or Regular Expressions.

Arrays & For Loops

A foreach loop can also be used to generate child properties.

$array: [ 1, 2, 3 ];

$result: {
	lines: foreach $i in $array {
		id: $i,
		total: {{ $i * 10 }}	// math expression
	}
	endfor
}

Will output:

{
	"lines": [
		{
			"id": 1,
			"total": 10
		},
		{
			"id": 2,
			"total": 20
		},
		{
			"id": 3,
			"total": 30
		}
	]
}

Arrays can also be filtered using | filter( condition), or conditional selection.