Skip to content

Projection

Mpl supports array index range for array access. e.g., [2:4] will index to array member 2 & 3 . If index is not specified as in, [], range is implied as 0 to len of array. 'wildcard' can be used as key in map access which means any key at the specified level. The result of range or wildcard index results in a list of Json values. e.g.,

x = json {"color":["red","purple", "green"]}
y = x.color[1:3]
y

output is:

"purple","green"

The type y is a Json list of size 2. In this case, list vals are array value. Consequently, the list can be operated upon in bulk. For example one can use y in an expression to change all the fields. e.g.,

y = "color " + y

output is:

"color purple","color green"

A Json list can be converted to Json type by json statement. e.g.,

a = json y
a

output is:

["color purple","color green"]

In case of map the projection can be done via wildcard. Mpl support unix glob syntax inside backtick. e..g, *bl*. Simple wildcards, like '' or 'xy' can be specified withouth backtics. e.g.,

x = json {"animals" : {"name": "cow"}, "wildanimals" : {"name": "lion"}}
x[*].name

output is:

"cow","lion"