Can you return CUSTOM query output as an OBJECT not an ARRAY?

Hey All

I’m building some queries into a JSON output that needs to go into an API request, and when I’ve used the standard query builder I’ve been able to use the ‘Single Query’ option to change the output from an array to an object (i think that’s the right terminology :slight_smile: )

So from this:

"json":[{
 "date":"2019-01-01T00:00:00.000Z",
 "calls":2006
}]

To this:

"json":{
 "date":"2019-01-01T00:00:00.000Z",
 "calls":2006
}

The problem is that I need to use a custom query for a couple of reasons (in the above, its to cast the format for the date as the default returned in the query isn’t accepted in the API)

But I don’t know how to replicate the same option with the standard queries to have it retun the data as an object rather than an array?

Any thoughts?

I’ve read a bit about JSON PATH but not sure how it fits in with Wappler and PostgreSQL.

Hi,

Have you tried sending the 0th index?
In your API call, just do something like: custom1[0]
The output will be same as a single query would give.

Thanks @sid that did indeed work.

I’m not exactly at the stage of the API call yet, just building out and testing the data structure. But I was able to remove the output of the query, and instead return the result of the query as a value using the 0 index like you suggested:

image

1 Like