Dear visitor, despite the COVID-19 outbreak, our team continues operating at full speed.

Also, here is the form where you can apply for a special discount and we will contact you with possible options. Stay safe and continue achieving your business goals.

Fill the form
Get Free Trial
Get Free Trial

What is the correct way to return empty result sets in the JSON API?

Answered
Tyler Ellis asked on March 13, 2020

Ahoy!
 
We’re using the JSON API for some of our reports, but whenever our query parameters result in an empty record set the Flexmonster client seems to break. I managed to find a workaround but I was hoping to get clarification on how we should be handling this.
 
We’re passing a URL into the Flexmonster constructor to fetch the data, and previously we would return an empty array: [] – this would result in the Flexmonster UI getting stuck on a “loading data” message and spinning forever.
 
I thought if we at least supplied the headers as the first item in the array it would work:

[
{ ...headers }
]

…but this also broke, displaying in an “invalid JSON” message.
 
I managed to find a workaround by including an empty object as the second entry:

[
{ ...headers },
{ }
]

This appears to correctly render an empty report.
 
Is that latter example the intended method for relaying empty result sets?

2 answers

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster March 18, 2020

Hi Tyler,
 
Thank you for giving us some time to look into this.
 
Please note that such behavior has already been reported before. The fix for this is going to be available in our next minor release ETA Mar 23rd. After the update, an empty grid will be displayed if an empty JSON object (“” or “[]”) is passed to Flexmonster.
 
We will make sure to inform you as soon as there are any updates on this. In the meantime, the mentioned workaround should be sufficient to avoid the error.
 
Please let us know if you have any other questions we can help you with.
 
Best regards,
Mykhailo

Public
Mykhailo Halaida Mykhailo Halaida Flexmonster March 24, 2020

Hi Tyler,
 
We are happy to let you know that loading empty CSV/JSON data was made consistent.
 
This is available in the 2.8.3 version of Flexmonster: https://www.flexmonster.com/release-notes/
Now an empty grid will be displayed if an empty JSON object (“” or “[]”) is passed to Flexmonster.
 
You are welcome to update the component: https://www.flexmonster.com/doc/updating-to-the-latest-version/
 
Please feel free to reach out to us if you have any questions we can help you with.
 
Best regards,
Mykhailo

Please login or Register to Submit Answer