I am trying to generate a JSON from the below Cobol structure using COBOL GENERATE statement of COBOL 6.3. I would like suppress the data elements in array based on their values. For example, would like to suppress model-value (ws-inx1,ws-inx2) in case if the value is spaces.
Can someone help me how I can achieve this using JSON GENERATE statement?
If not possible with JSON GENERATE , is there anyway we can generate JSON in a COBOL-CICS program. I have checked the possibility of CICS JSON assist, but could not see any suppress option.
COBOL copybook structure.
01 payload
03 reference-id pic x(10).
03 model-specific-data occurs 5 times indexed by ws-inx1.
05 model-id pic x(10).
05 model-values occurs 5 times indexed by ws-inx2.
10 model-attrib-name pic x(01).
10 model-value pic x(3).
10 model-value-boolean pic x(05).
88 true-val value 'true'.
88 false-val value 'false'
Sample JSON expected
{
"payload": {
"reference-id": "abc123",
"model-specific-data": [
{
"model-id": "model 01",
"model-value-attribs": [
{
"model-attrib-name": "a",
"model-value": "A01",
"model-value-boolean": true
},
{
"model-attrib-name": "b",
"model-value": "123",
"model-value-boolean": false
},
{
"model-attrib-name": "x",
"model-value-boolean": false
}
]
},
{
"model-id": "model 02",
"model-value-attribs": [
{
"model-attrib-name": "c",
"model-value": "C01",
"model-value-boolean": true
},
{
"model-attrib-name": "d",
"model-value": "D01",
"model-value-boolean": false
}
]
}
]
}
}
Sorry I was a little too quick with my previous reply. JSON GENERATE does have everything to obtain what you want. I only changed boolean to 1 character for JSON GENERATE expects 1 char only for boolean.
Source:
Result displayed: 0491 {"payload":{"reference-id":"abc123","model-specific-data":[{"model-id":"model 01","model-values":[{"model-attrib-name":" a","model-value":"A01","model-value-boolean":true},{"model-attrib-name":"b","model-value":"123","model-value-boolean":fa lse},{"model-attrib-name":"x","model-value-boolean":false}]},{"model-id":"model 02","model-values":[{"model-attrib-name" :"c","model-value":"C01","model-value-boolean":true},{"model-attrib-name":"d","model-value":"D01","model-value-boolean": false}]}]}}