Error if comment in json when using Ext.decode() in ExtJS 7

394 Views Asked by At

Ext.decode() is very strict now. It throws error when there's a comment in the JSON or any invalid json format, such as no double quote. How can I disable such checking?

Ext.decode('{ test: test}');
OR
Ext.decode(`{//test 
    "include": [
        "main.json"
    ]
}`)

Uncaught Error: You're trying to decode an invalid JSON String:

But this will not throw error in 6.2.0

1

There are 1 best solutions below

0
On

Like devbnz mentioned, there's a 2nd param, if set to true, method wont throw an error and will return null instead. https://docs.sencha.com/extjs/6.5.3/classic/Ext.html#method-decode

But yet prior to 6.6.0, Ext.decode() still can accept invalid json. It was fixed in 6.6.0 https://docs.sencha.com/extjs/6.6.0/guides/whats_new/release_notes.html

EXTJS-18443 JSON decoder should throw exception on invalid syntax

[UPDATE] My answer is wrong. There's no solution for now. You cannot decode a JSON with comment using Ext.decode in ExtJs7