Dynamic parameters

Formatters accept dynamic variables if parameters start with a . and are not surrounded by quotation marks.

The following dataset is used in the examples below.

Data

{
  "id" : 10,
  "qtyA" : 20,
  "subObject" : {
    "qtyB" : 5,
    "qtyC" : 3
  },
  "subArray" : [{
    "id" : 1000,
    "qtyE" : 3
  }]
}

To do mathematical operations:

{d.subObject.qtyB:add(.qtyC)} // 8 (5+3)

To insert parent attributes, 2 dots .. have to be used. To access to grandparents attributes, 3 dots ... are necessary, etc.:

{d.subObject.qtyB:add(.qtyC):add(..qtyA)} // 28  (5+3+20)

To read parent objects and their children attributes (no limit in depth):

{d.subArray[i].qtyE:add(..subObject.qtyC)} // 6 (3+3)

It returns an error if the attribute does not exist:

{d.subArray[i].qtyE:add(..badAttr)} // [[C_ERROR]] badAttr not defined

It returns an error:

{d.subObject.qtyB:add(..subArray[0].qtyE)} // [[C_ERROR]]

It returns an error if the sub-array is not indexed:

{d.subObject.qtyB:add(..subArray[i].qtyE)} // [[C_ERROR]] subArray[i] has no index

Last updated