Bug in DataUtil.parse.parseJson ?

Hi,

I'm running into a javascript error from the code in Essential J2 2 (version 16.3.22). I'm using the Grid, which is using the Url adaptor, with JSON data. I've traced the error down to the DataUtil.parse.parseJson function. Most JSON data passes, but some don't.

You can reproduce the error if you do this:

import { DataUtil } from '@syncfusion/ej2-data';

let data = DataUtil.parse.parseJson({
    "x": ["{y()}"]
});

or also this

let data = DataUtil.parse.parseJson({
    "x": [null]
});

It sounds like a (super painful) bug to me. Can you confirm? Can that be fixed or hotpatched in any way?

Thanks
Simon.

9 Replies

MF Mohammed Farook J Syncfusion Team October 1, 2018 07:19 AM UTC

Hi Simon, 
 
Thanks for contacting Syncfusion support. 
 
We have validated your code example and we found that you have passed invalid JSON string .  could you please example as follows: 
 
 
var d =  var a = {"x":[ {y: 1}]}  
 
var dataString = JSON.stringify(a); 
 
var data = DataUtil.parse.parseJson(dataString)  
// Or 
var data1 = DataUtil.parse.parseJson({"{"x":[{"y":1}]}"}); 
 
var data2 = DataUtil.parse.parseJson ('{"x":[{"a":null}]}') 
 
 
 
The Essential JS2 “DataUtil.parse.parseJson” can convert only valid JSON string only. 
 
Please get back to us if you need further assistance. 
 
 
Regards, 
J Mohammed Farook 



SI Simon October 1, 2018 09:40 AM UTC

Hi,

What you say is quite untrue. Please note

{
    "x": ["{y()}"]
}

and

{
    "x": [null]
}

are perfectly valid JSON (an array can contain one string or one null value). I'm using these two exact examples because they cause errors. You're not using the same JSON in your answer.

Also contrary to what you say, DataUtil.parse.parseJson supports string, arrays and object. The source is available here: https://github.com/syncfusion/ej2-data/blob/master/src/util.ts#L1564

and this is precisely what causes the issue with Grid/Adaptors, etc.. When you pass JSON as a string, there is no problem with parseJson, the problems only appears when passing an object (like in my code above), which seems to be what the grid+adaptor code does undercovers. Again, this works with many objects, it's not failing all the time, use my samples.






RS Renjith Singh Rajendran Syncfusion Team October 2, 2018 01:57 PM UTC

Hi Simon, 

Thanks for the update. 

We have validated the reported problem. We need more details to further look into this problem, and provide you a solution. Please share with us the following details for better assistance, 

  1. Share the details about the data types available in your JSON data
  2. Share with us the data structure you are using in your sample.
  3. Share if any script error appears in the console.
  4. Share the full Grid code.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith Singh Rajendran. 




SI Simon October 2, 2018 03:11 PM UTC

Hi,

Thanks for this update. Well, it's easy to reproduce you can just use my initial code. It seems related to some regex used by parseJson IterateXXX methods...

Anyway, I have built a small reproducing project, attached to this thread. Basically the problem happens as soon as we send a somehow special JSON result to the UrlAdaptor, for example:

{
  "count": 1,
  "result": [
    {
      "name": "bill",
      "whatever": [ "{x()}" ]
    }
  ]
}

If I change the value of "whatever" to something else, everything works fine. Note null is also an issue, as stated in my first email.

Thanks.
Simon.

Attachment: WebApplication5_b75b00af.zip


MF Mohammed Farook J Syncfusion Team October 4, 2018 08:11 AM UTC

Hi Simon, 
 
Query: If I change the value of "whatever" to something else, everything works fine. 
 
We have analyzed your query and we suggest to use valueAccessor property of the grid to access the array type values of the grid columns. Using this property, we can obtain the field array values in the data parameter and manipulate it according to the requirement. Please refer to the below documentation and attached screenshot for your reference. 
 
Code example: 
 
... 
    function valueAccessor(field, data, column) {             //data in the form of  
                                                         [{“name”:”bill”},”whatever”:”[{“valueone”:”value”},{“value2”:”val”}]”] 
       return data.CustomerID[0].cu; 
    } 
... 
 
 
Screenshot: 
 
 
 
Please get back to us for further assistance. 
 
 
Regards, 
J Mohammed Farook 
 



SI Simon October 4, 2018 08:18 AM UTC

Hi,

You don't seem to understand.

I don't want to change my JSON nor I need help to read these array values. I don't want to read these values, I just need SyncFusion code to not fail when it tries to parse a correct JSON stream.

A.k.a: it's a bug, a Javascript exception is raised in your parseJson code, so I'd like you guys to fix it, I spent some time to create a reproducing project.


MF Mohammed Farook J Syncfusion Team October 5, 2018 11:56 AM UTC

Hi Simon, 

We are able to reproduce the reported issue at our end. So we have logged “parse error when valid json values are passed into DataUtil.parse.parseJson” as a bug and the fix for this issue will be available in any of our upcoming patch release. 

We appreciate your patience until then. 

Regards, 
J Mohammed Farook. 
 



SI Simon October 16, 2018 04:01 PM UTC

I've tested the latest version, and it's fixed now. Wonderful!

Thanks a lot.


MF Mohammed Farook J Syncfusion Team October 17, 2018 08:20 AM UTC

Hi Simon, 
 
Thanks for your update.

We are happy to hear that your problem has been resolved.

Please get back to us if you need further assistance from us.

Regards,
J Mohammed Farook
 


Loader.
Up arrow icon