'Trying to selectively forgo quotes when serializing a structure to JSON
I am querying SQL and using that and ColdFusion [2018] to build a struct containing a JS schema. After building the structure, I use serializeJSON and pass it to my JS [side note: Kendo UI]. Below is that resultant JSON that has been getting generated [approx]:
const dataModel = { id:"ID",
"fields": {
REPORTTITLE : {
nullable : false,
"hidden" : false,
type : "string",
template : "reportTitleTemplate",
filterable : "{delay : 1500}"
},
ISACTIVE : {
nullable : false,
"hidden" : false,
type : "boolean",
template : "booleanTemplate",
filterable : true
},
COLUMNGROUPING : {
nullable : false,
"hidden" : false,
type : "string"...and so on...
}
}
};
The obvious problem I'm running into is two fold. 1st- For some reason the key hidden, and only hidden, is being quoted. It is possible that this my fault due to some random 'fix' buried deep in a service, but I doubt it. I can resolve this, I suppose. 2nd-[and this is my main concern] I need a way to effectively signal that values for the key Template do not get quoted. The same goes for filterable when it is itself a struct. I need the above to output as below instead:
const dataModel = { id:"ID",
"fields": {
REPORTTITLE : {
nullable : false,
hidden : false,
type : "string",
template : reportTitleTemplate,
filterable : {delay : 1500}
},
ISACTIVE : {
nullable : false,
hidden : false,
type : "boolean",
template : booleanTemplate,
filterable : true
},
COLUMNGROUPING : {
nullable : false,
hidden : false,
type : "string"...and so on...
}
}
};
I abhor the thought of using ReReplace or the like.
Differentiating filterable values of true/false versus structs, I can work all of that out, "hidden" would be light enough if I need to do a replace on that alone.
I am just hoping that someone has run across this situation before and discovered something a little more elegant than a brute force replace for the template and filterable keys [or whatever key/value pair, obviously].
These reports do get very massive and I'm on a bit of a cycles/request vigilance kick...
Any input is appreciated, I've found practically another on this topic.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
