JSON String formatting Cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

JSON String formatting Cobol

Postby manju23 » Wed Aug 11, 2021 4:12 pm

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.
manju23
 
Posts: 1
Joined: Wed Aug 11, 2021 4:02 pm
Has thanked: 0 time
Been thanked: 0 time

Re: JSON String formatting Cobol

Postby oliver07 » Sat Oct 30, 2021 2:32 pm

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.
oliver07
 
Posts: 1
Joined: Sat Oct 30, 2021 2:28 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post