Question

How to parse API JSON response that is just an array

  • 16 October 2023
  • 2 replies
  • 211 views

Badge +2

I’ve run into an issue with the Json response body of an internal API. A successful POST request will return an array of JSON objects but without a parent or root name. This is causing some trouble with the JSON package as it needs a root name in order to fetch the node value.

 

Is there another package that can parse this data without needing an object root name?

 

Below is an example of the response:

[
{
"mrn": "211757",
"firstName": "Tester",
"lastName": "Jimmy",
"dateOfBirth": "2022-02-02",
"gender": "None",
"county": "",
"homePhone": "111-111-1111",
"workPhone": "222-222-2222",
"cellPhone": "333-333-3333",
"email": "b@h.com",
"primaryPhone": "None",
"codeStat": "Ycanth RPh",
"category": "Ycanth",
"insCoord": "",
"primaryRN": ""
},
{
"mrn": "211758",
"firstName": "Tester",
"lastName": "Jimmy",
"dateOfBirth": "2022-02-02",
"gender": "None",
"county": "",
"homePhone": "111-111-1111",
"workPhone": "",
"cellPhone": "",
"email": "b@h.com",
"primaryPhone": "None",
"codeStat": "Ycanth RPh",
"category": "Ycanth",
"insCoord": "",
"primaryRN": ""
},
{
"mrn": "211759",
"firstName": "Tester",
"lastName": "Jimmy",
"dateOfBirth": "2022-02-02",
"gender": "None",
"county": "",
"homePhone": "111-111-1111",
"workPhone": "",
"cellPhone": "",
"email": "",
"primaryPhone": "None",
"codeStat": "Ycanth RPh",
"category": "Ycanth",
"insCoord": "",
"primaryRN": ""
}
]

 


2 replies

Badge

you can use 0.mrn for 211757, 1.mrn for 211757 etc.

Badge +3

Hello @bmhelton,

 

Json Response body will always be string, in this scenario what u can do is 

split the string with “},”, this results in List


Loop through the list and using string:extract, u can get the value u requires
 

NOTE: In this case i’m trying to get only ‘mrn’ value

Hope this helps u

Reply