COBOL

COBOL

COBOL

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

 View Only
Expand all | Collapse all

Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

  • 1.  Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

    Posted Thu October 13, 2016 07:59 AM

    Hi All,

    Based on my project requirements, I need to parse the JSON string into a COBOL copybook and do the functional processing on them. 

    For parsing this JSON data (in textpad, and can FTP to MF), we do have the required modules HWTJPARS/HWTJINIT in our library. But i have no clue how to use this in the cobol program.

    Could you please advise with some program examples?

    Harry01


  • 2.  Re: Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

    Posted Fri October 14, 2016 08:35 AM

    Can someone please help here?

    Harry01


  • 3.  Re: Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

    Posted Mon October 17, 2016 12:56 PM

    Harry,

      First of all, I would read the documentation of the product: http://publibz.boulder.ibm.com/zoslib/pdf/OA46575.pdf

     

    Second, you could look at a presentation that I wrote about it, which I will attach here.

     

    Tom

    Tom.Ross


  • 4.  Re: Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

    Posted Tue October 18, 2016 07:11 AM

    Thanks  Tom. 

     

    I had a chance to read the product documentation in the IBM sites. The presentation looks awesome. 

    I am building my code to test the parser.

     

    Thanks,

    Harry

    Harry01


  • 5.  Re: Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

    Posted Thu October 20, 2016 10:54 AM

    Hi Tom,

    I have got the following queries. Could you please advise. 

    Apologies if my queries are naive.

     

    1)  Do I need to include any copy member for accessing these variables in the program ?

         HWTJ_WARNING,     HWTJ-RETURN-CODE,     HWTJ-PARSERHANDLE,     HWTJ-DIAG-AREA,      HWTJ-HANDLE etc


    2)   At some places, i also get chinese characters in the input UTF-8 JSON string, how will i convert this to EBCDIC format? please advise.

    3)   While calling HWTJSRCH, what values to be passed to these parameters - ObjectHandle, StartingHandle

    4)  While calling HWTJGAEN, what is the significance of this statement and where this index is used - SET REQUEST-ARRAY-INDEX TO 1

    5)  In PROCESS-REQUEST-INFO para, there is call like this (CALL 'findstring' ). Please advise if i need to use this statement as is, since i dint get any clue what is 'findstring'.

    6)  Is HWTJTERM mandatory?

    7)  Let say I have a structure like this, and lets say, i have searched m_Address pointer using HWTJSRCH and called "HWTJGNUE", "HWTJGAEN" modules.
            and did a  look up for the string m_address-id and get the value 1155. Then in the same way. let me read country and state.
            Now how will i look up the another address-id? Will the parse handle navigate to the successive strings one by one? Please advise.
            
             "m_Address":       [
                      {
                    "m_address-id": 1155,
                   "m_cntry_cd": "USA",
                   "m_state": "IN"
                }
                    "m_address-id": 1144,
                   "m_cntry_cd": "USA",
                   "m_state": "CA"
                }
    ]

    8)  In the same way, like address, i do have phone and mail details in different arrays. For these, i will search from the root variable like we did for m_Address array? Please advise.

    The flow i considered for m_address is :

    HWTJINIT

    HWTJPARSE

    HWTJSRCH (MOVE 'm_Address' TO WS-SRCH-STR           MOVE X'00000000' TO HWTJ-HANDLE        )

    HWTJGNUE  (this will get the num of entries... for eg :  2 considering the above example)

    HWTJGAEN  (loop this based on num of entries)

                    MOVE 'm_bldg_nb' TO WS-SRCH-STR                         
                    CALL 'findstring'          USING                        

                    end loop

     

    Harry01


  • 6.  Re: Need help in using HWTJPARS in COBOL for parsing a JSON string. Any sample available?

    Posted Wed November 02, 2016 12:23 PM

    Harry,

      Most of these are all specific questions for the z/OS Client Web Enablement Toolkit product, can you ask these questions to that product?

    For 2), you cannot parse JSON text with Chinese characters using the z/OS Client Web Enablement toolkit parser.  You cannot convert Chinese characters in UTF-8 into EBCDIC.

    Maybe that is all you need to know, that you cannot use the z/OS Client Web Enablement Toolkit parser? 

    We are working on a JSON parser in COBOL that will handle UTF-8 input, but it will not be ready to ship for quite some time, at least late 2017.  In the meantime, you could prepare by migrating to COBOL V6 to be ready for the new version or release of COBOL!

     

    Tom

    Tom.Ross