Read json starting with [ or { according the amount of returned items

Created on 27 January 2016, almost 9 years ago
Updated 13 August 2023, over 1 year ago

Hi,

I'm integrating an external service that provides his own API.

The API works like this:

When there are no results, it returns an empty array: "[]" - No issues.
When there are multiple results, it returns an array with the json objects: "[{ob1}, {obj2}, ..., {objN}]" - No issues.
But, when there is only one result, it returns the single object: "{obj1}"

What I expected is the API to return an array with only one object like this: "[{obj1}]"

I tried different apath characters to parsing this correctly:
If I use "[" or "/" or "." and there is only one result, it raise a fatal error (because it can't read a property name).
If I use "{", I don't see any fatal error but it's interpreted as if there are no results, so I see an empty view.

Could please advise how to properly configure this or maybe provide a patch to handle the "[{}]" and "{}" situation?

Thanks.

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡·Argentina drupal-son

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024