Page 1 of 1

JSON String formatting Cobol

PostPosted: Wed Aug 11, 2021 4:12 pm
by manju23
Hi all,

I would like to replace "true" by true and "false" by false in a JSON formatted string in Cobol.

For eg : a:"true" need to be replaced as a:true and b:"false" need to be replaced by b:false.

The replacement should happen for all occurences of "true" and "false" in the string .

Basically the requirement to send true or false values in string without being enclosed in quotes.

Re: JSON String formatting Cobol

PostPosted: Sat Oct 30, 2021 2:32 pm
by oliver07
var j = '{"field1":"true","field2":"false"}';

var o = JSON.parse(j, (k, v) => v === "true" ? true : v === "false" ? false : v);

console.log(o);

I think this might help you with your problem.