Skip to main content
Question

How to parse API JSON response that is just an array


Forum|alt.badge.img+3

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

Forum|alt.badge.img
  • Cadet | Tier 2
  • 1 reply
  • October 17, 2023

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


satyasaikrishna0209
Forum|alt.badge.img+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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings