/
JSON Support

JSON Support

JSON documents can be created in PhixFlow using the toJson function and the output modified using the following notations.

Curly Brackets { }

  • Use curly brackets to create an object, e.g. { "FirstName" : "John", "LastName" : "Smith", "Age" : 50 } 

Colon : and Dot . 

  • Use a colon to define a key-value pair, e.g. { "key" : "value" } 
    • The key must always evaluate to be a string
    • The value must always evaluate to be a string, number, object, array, boolean or null
  • Use a dot to access the key and value, e.g. $foo.key:$foo.value 

Example using curly brackets, colon and dot

Input
{
forEach(

//Convert the data from the lookup, getCo, to JSON and store it in the variable $company
	$company, toJson(getCo),

/*Using the $company object, create a key-value pair where the key is the Company Name and the value is an object containing two key-value pairs of the CompanyID:value and Industry:value*/
	$company.CompanyName : $company.CompanyID:Industry
	
)
}
Returns
{
  "Romaguera Inc" : {
    "CompanyID" : 108,
    "Industry" : "Manufacturing"
  },
  "Becker and Sons" : {
    "CompanyID" : 112,
    "Industry" : "Manufacturing"
  },
  "Larson Inc" : {
    "CompanyID" : 398,
    "Industry" : "Manufacturing"
  }
}

At @ and Dollar $

  • @ can be used to reference the current object
    • It allows access to any key-value pairs that have already been set
    • Use the syntax @.^. to traverse upwards 
  • $ can be used to reference the outer object of the current object being created
    • It will allow access to any key-value pairs that have already been set 

Example using @ 

Input
{

forEach(
        $company, toJson(getCo),

        $company.CompanyName : {$company,"CompanyName" : toUpper(@.CompanyName)}
)
}

Note the use of @ as a shortcut for the current object, which is $company. 

Returns
{
  "Romaguera Inc" : {
    "CompanyID" : 108,
    "CompanyName" : "ROMAGUERA INC",
    "Industry" : "Manufacturing"
  },
  "Becker and Sons" : {
    "CompanyID" : 112,
    "CompanyName" : "BECKER AND SONS",
    "Industry" : "Manufacturing"
  },
"Larson Inc" : {
    "CompanyID" : 398,
    "CompanyName" : "LARSON INC",
    "Industry" : "Manufacturing"
  }
}

Example using $

Input
{
"Count":2,
forEach(
        $company, toJson(getCo),

        $.Count : {$company,"CompanyName" : toUpper($company.CompanyName)}
)
}

Note the use of $.Count as a shortcut for the outer object of the current object being created.

Returns
{
  "Count" : 2,
  "2" : {
    "CompanyID" : 398,
    "CompanyName" : "LARSON INC",
    "Industry" : "Manufacturing"
  }
}

Related content

PhixScript Cheat Sheet
PhixScript Cheat Sheet
Read with this
JSON Support
JSON Support
More like this
JSON Support
JSON Support
More like this
JSON Action Properties
JSON Action Properties
More like this
JSON Node
JSON Node
More like this
JSON Node
JSON Node
More like this