COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.

 View Only

IBM Enterprise COBOL - JSON GENERATE - How to generate an empty object?

  • 1.  IBM Enterprise COBOL - JSON GENERATE - How to generate an empty object?

    Posted Sat September 14, 2024 11:31 AM

    Hi,

    We want to create JSON documents that include empty objects, i.e. "myobject": {} which is allowed by the standard at the level of a JSON document.

    Apparently this is not possible with the COBOL JSON GENERATE instruction: if all the child elements of a group are deleted, then the parent element is also deleted...

    Sample:

    Working-storage section.                           
    01  jsonDoc pic U(2048).                           
    01  jsonDoc-length pic S9(8) COMP-5.               
    01  rootObject.                                    
        05  myObject1.                                 
            10  myData1 pic X(10).                     
        05  myObject2.                                 
            10  myData2 pic X(10).                     
    Procedure division.                                
    MAIN.                                              
        move 'hello' to myData1                        
        move spaces  to myData2                        
        json generate jsonDoc from rootObject          
             count in jsonDoc-length                   
             suppress myData2 when spaces              
        end-json                                       

    Observed result:

    {"rootObject":{"myObject1":{"myData1":"hello"}}}

    Expected result:

    {"rootObject":{"myObject1":{"myData1":"hello"}, "myObject2":{}}}

    How to achieve this result?

    We should have an option that disables the deletion of the parent object.

    Thanks.



    ------------------------------
    Denis FALLAI
    BPCE SI, BPCE group.
    ------------------------------