JsonValue

This article describes the formula syntax and usage of the JsonValue function in GoFormz.

Description

JsonValue extracts an object or an array from a JSON string

Syntax

JsonValue(expression, path)

  • expression Typically the name of a field that contains JSON text.
  • path A JSON path that specifies the property to extract.

If the format of path isn't valid, JsonValue will not return anything.

Examples

Copy the following JSON into a Text field on your Template, and name the field JSON

{
   "info":{
      "type":1,
      "address":{
         "town":"Bristol",
         "county":"Avon",
         "country":"England"
      },
      "tags":[
         "Sport",
         "Water polo"
      ]
   },
   "type":"Basic"
}
PathFormulaResult
$.info.address=JsonValue([JSON], "$.info.address"){"town":"Bristol", "county":"Avon", "country":"England"}
$.info.address.town=JsonValue([JSON], "$.info.address.town")Bristol
$.info.address.faketown=JsonValue([JSON], "$.info.address.faketown")
$.info.type=JsonValue([JSON], "$.info.type")1
$.tags=JsonValue([JSON], "$.tags")["Sport", "Water polo"]
$.tags[1]=JsonValue([JSON], "$.tags[1]")Water polo

The JsonValue function in GoFormz can be used to extract information from other fields in GoFormz, like Location or Image fields.

For example, this is what the JSON in a Location field (Map view) would look like:

{
   "Latitude":32.7155712,
   "Longitude":-117.1652608,
   "Accuracy":1427,
   "AttachmentId":"891b74de-08f1-40c8-a5eb-e57b673c626d",
   "FileId":"22183a4e-a174-473e-8008-a76f51c67470"
}

And this is an example of the JSON data in an Image field:

{
   "FileId":"ba5194e0-bc7c-4bca-a4c8-8814715a1e27",
   "AttachmentId":"50b76508-84ab-41df-a74b-6c3ebd0cbdb4"
}

Here are a few examples of formulas you might use to extract the information from a field in GoFormz

FormulaResultDescription
=JsonValue([Location], "$.Latitude")32.7155712Looks in the field named "Location" for the JSON path with the name of Latitude
=JsonValue([Location], "$.Longitude")-117.1652608Looks in the field named "Location" for the JSON path with the name of Longitude
=JsonValue([Image], "$.FileId")ba5194e0-bc7c-4bca-a4c8-8814715a1e27Returns the value from the name "FileId" in the field named "Image"