Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
namephixScript
nopaneltrue

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

Page Contents

Table of Contents
maxLevel3
outlinetrue
indent12px
stylenone

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

Code Block
titleInput
{
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
	
)
}


Code Block
titleReturns
{
  "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 @ 

Code Block
titleInput
{

forEach(
        $company, toJson(getCo),

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

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

Code Block
titleReturns
{
  "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 $

Code Block
titleInput
{
"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.

Code Block
titleReturns
{
  "Count" : 2,
  "2" : {
    "CompanyID" : 398,
    "CompanyName" : "LARSON INC",
    "Industry" : "Manufacturing"
  }
}