Get Free Trial

Data Server JSON

Answered
Scott Oliver asked on July 30, 2021

Hello,
We have noticed a discrepancy between the way that data server and your local client process JSON.
 
When parsing the data to a local version, the following JSON works perfectly fine:
 

var jsonData =
[
{
'Color' : 'green',
'Country' : 'Canada',
'State' : 'Ontario',
'City' : 'Toronto',
'New' : 'Field',
'Price' : 174,
'Quantity' : 22
},
{
'Color' : 'red',
'Country' : 'USA',
'State' : 'California',
'City' : 'Los Angeles',
'Price' : 166,
'Quantity' : 19
}
];

 
However, flex data server rejects this for the following two reasons:

  • Quotations must be of the double variety (“such as this” and ‘not this’)
  • The first packet of JSON must include all of the fields that will be used throughout

Unfortunately for our use case, the second point is not an option (the first is just an annoyance). Is there any way that we can work around this issue?

5 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster July 30, 2021


Hello, Scott,
 
Thank you for reaching out to us.
 
Concerning quotation, please note that JSON requires using double quotes according to the specification. Single quotes and unquoted strings can only be used when operating with inline JSON in scripts.
 
Talking about the first packet, it requires all the fields to be present. The first entry is used to construct the internal structure of the data set and resolve fields' data types.
When connecting directly to JSON, fields absent in the first entry will be ignored as well: https://jsfiddle.net/flexmonster/t743fpkj/ (the "New" field is not displayed in the Field List).
We have moved the "New" field from your example to the second element of the array. Otherwise, the mentioned dataset loads normally both directly and using the Data Server.
 
We hope it helps.
Feel free to contact us if other questions arise.
 
Kind regards,
Illia

Public
Scott Oliver July 30, 2021

Unfortunately, this does not solve our problem, as we cannot store all of the information in all of the elements. The first element may miss particular objects that are present in the following elements. This is where we would prefer to use the JSON header, but I presume this is not compatible with data server?

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster July 30, 2021

Hello,
 
Thank you for your feedback.
 
You are right about the fact that the header JSON object is not supported for the Data Server.
However, please note that you do not need to store all the information in all of the elements. Similar to the mentioned header object, it is enough to mention all available fields in the first object of the data set.
 
Do not hesitate to contact us if other questions arise.
 
Kind regards,
Illia

Public
Scott Oliver August 6, 2021

Yes, however, if we were to include a blank element (where all of the objects had been noted but set to empty values), this would still be parsed into the report, and show blank values for all columns.

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster August 6, 2021

Hello, Scott,
 
This is due to the fact that Flexmonster Data Server uses values of the first record to identify the data type of the corresponding field. This datatype will be applied to the following records across the dataset.
 
In its turn, an empty value does not provide any information about the nature of the field. As a result, the Data Server is unable to predict the field’s type and ignores it.
 
Please let us know if other questions arise.
 
Kind regards,
Illia

Please login or Register to Submit Answer