Hey Coda, I have a JSON string here, but I only need parts of it to accomplish what I need. Can you just give me the info I need?
ParseJSON() has two parameters.
A string of JSON text.
They key for the value to extract.
Don’t let this formula intimidate you - ParseJSON() is crucial for working with Codas Webhook Invoked automations. To understand how this formula works, though, you must first understand what JSON is.
What is JSON
Let’s break that down 👇
Basic JSON structure
What are values?
Values in a JSON object always come second in a pair and are on the right-hand side of the :. Values are the information you actually want and are after.
For example, the JSON object below represents some information about a person. The valuable information is not necessarily that this person has a name (aka the key) but rather that that persons name happens to be Bob (aka the value within the key/value pair)
JSON with nested structure
A JSON object can also have nested properties. In the past example, we had a JSON object representing a person that contained information about that person.
Here is an example of a more complex JSON object that represents a person
Objects can also contain things called arrays which are similar to a simple list in Coda. The square brackets [ designate the end and beginning of an array and items within an array are separated by a ,.
Below, the Bob JSON object is storing the information that he has 3 children and their corresponding names.
Accessing Values in JSON
JSON is only useful to you in Coda when you can access the data you want. The Path parameter of ParseJSON() is the means by which you will access specific information in a JSON object.
But there are specific rules by which you can access JSON especially when it comes to nested objects. Let’s try it out below!
Accessing keys that with a simple non-nested value
In order to access objects that are not nested in any way and do not contain any arrays, simply type in the key as the Path parameter for your formula