How do I extract only the values from a json file obtained via API/GET? I’m saving the extracted json to an Okta table. Example, I’m seeing [“Development”] but only want Development.
Hi there,
There are two approaches:
- Format the value you get from the table.
- Format the value before you save it into the table.
For #1, you can try the following steps:
For #2, you can use the Get card to get the value from the API response in a format you need and then save it into a table.
Please share your JSON if you can, but the following links will help you learn about extracting data from a JSON object:
Hi Max,
The examples with example data work but I’m doing something wrong when trying to do the same thing using my json data. Here’s the beginning of my json showing the first object.
What is the path for the “department” value?
{
“computers”: {
“size”: [
“6010000000”
],
“computer”: [
{
“id”: [
“999”
],
“name”: [
“Mareme”
],
“managed”: [
“true”
],
“username”: [
“”
],
“model”: [
“13-inch MacBook Pro”
],
“department”: [
“SC”
]
}
Here are a few tips:
- Sometimes, using a tool like https://jsonpathfinder.com/ (or equivalents in a code editor, etc.) can be helpful.
The [0]
parts in the path indicate that I’m looking at the first item in a list (aka array). The links Max shared should help here, but you can use “List” function cards or dot notation within an Object - Get card to start digging into the object.
I’ve made your JSON example a little more complex with two objects within the computer list (your example didn’t seem quite valid, so it threw an error in my JSON Parse card).
Click to see my example JSON
{
"computers": {
"size": ["601000"],
"computer": [{
"id": ["999"],
"name": ["Mareme"],
"managed": ["true"],
"username": ["example@test.com"],
"model": ["13-inch MacBook Pro"],
"department": ["SC"]
},
{
"id": ["123"],
"name": ["Bryan"],
"managed": ["false"],
"username": ["test@example.com"],
"model": ["15-inch MacBook Pro"],
"department": ["DC"]
}]
}
}
- I use a path of
computers.computer.0.department.0
to get the text value"SC"
in my Object - Get Multiple card.computer
is a list of objects, we use.0
to specify the first object in the list that contains the"SC"
department value we’re looking for.department
is a list of text, so we use.0
in the path to specify that we want the first (and, in this case, only) value from that list.- This article goes into more detail: Okta Workflows How-To: Read a JSON Path With Dot-Notation. Let us know if you have questions.
Workflows are flexible, and there are often multiple ways to retrieve values and accomplish tasks - the “best” to choose depends on your use case. To share another example that uses list functions (rather than dot notation) to retrieve the values:
The path worked! TYVM @bryan.barrows and @maxkatz. I really appreciate your time and help!