if
Syntax
`# Statements``# Statements`Details
if (($JSON{example}.[status] == "OK") || (${override} == "enabled")) {
# Execute if the status is "OK" or if we have set ${override} to "enabled"
}Example
Last updated
`# Statements``# Statements`if (($JSON{example}.[status] == "OK") || (${override} == "enabled")) {
# Execute if the status is "OK" or if we have set ${override} to "enabled"
}Last updated
var JSON_dir = "examples\json"
buffer example = FILE "${JSON_dir}\doc.json"
var title =
# For every element in the 'items' array ...
foreach $JSON{example}.[items] as this_item
{
# Extract the item name and id
var item_name = $JSON(this_item).[name]
var sub_id = $JSON(this_item).[id]
if (${sub_id} == 02) {
# For every child of the 'subvalues' object ...
foreach $JSON(this_item).[subvalues] as this_subvalue
{
# Get the subvalue name and value
var sub_name = ${this_subvalue.NAME}
var sub_value = ${this_subvalue.VALUE}
# Render an output line
print ${title} (id:${sub_id} -> Item: ${item_name} -> Subvalue:${sub_name} = ${sub_value}
}
} else {
print Skipping unwanted id: ${sub_id}
}
}
discard {example}
terminate Skipping unwanted id: 01
Example JSON data (id: 02) -> Item: Item number two -> Subvalue:0 = 10
Example JSON data (id: 02) -> Item: Item number two -> Subvalue:10 = 442
Example JSON data (id: 02) -> Item: Item number two -> Subvalue:100 = 783
Example JSON data (id: 02) -> Item: Item number two -> Subvalue:1000 = 1009