Skip to main content

I have a simple cobol program that currently receives a json payload from another cobol program (via an API type call).  We have a need for a C++ program to be able to pass the same json string to the cobol program via the existing api calling method (currently oracle tuxedo).

I have a working cpp client and its json is structured correctly, the json it pretty simple and is along the lines of the following:

{ "APICALL": {"APINAME":"DUMMYAPI", "APIPARAMS": {"PARM1":"VALUE1", "PARM2": "VALUE2"}}}

The cobol program that is receiving the API call needs to extract the APINAME and pass the APIPARAMS string when calling the cobol module named in "APINAME".

I need to be able to just pass the value of APIPARAMS on, if I have something like the following defined:


01 API-CALL.
03 API-NAME PIC X(30).
03 API-PARAMS PIC X(400).

If I "JSON PARSE" it I end up with binary "junk" in API_PARAMS (API-NAME is spot on) in my cobol program, unless I call if from another cobol program.  When that happens it appears that cobol is putting "\\" in string for APIPARAMS around the quotes and works.  I understand why it should work as its just a quoted string at that point, however my Cpp code uses a web framework so it creating a proper json input as seen above, ie no backslashes.

Question is how do I get the "string" side of API_PARAMS via JSON PARSE or is it not possible?  I know I can define the elements in API_PARAMS and that works, but I don't need to access the params individually, plus they might be different for different calls. In fact my COBOL program is pretty agnostic and just needs to pass the json string (I know its not technically a string, its a map) to the next module it calls.  It then returns the results back to the calling system, essentially its just a simple pass through interface.

I  apologise in advance as I'm not a cobol programmer and haven't done cobol for decades so my terminology etc might be off, but I've googled till I'm running out of the will to live.  Initially I thought it was my cpp program that was sending in duff data but its actually correct, it seems to be how COBOL does or doesn't allow the dumping of the whole of the JSON Map "API_PARAMS".

Thanks in advance


#VisualCOBOL

I have a simple cobol program that currently receives a json payload from another cobol program (via an API type call).  We have a need for a C++ program to be able to pass the same json string to the cobol program via the existing api calling method (currently oracle tuxedo).

I have a working cpp client and its json is structured correctly, the json it pretty simple and is along the lines of the following:

{ "APICALL": {"APINAME":"DUMMYAPI", "APIPARAMS": {"PARM1":"VALUE1", "PARM2": "VALUE2"}}}

The cobol program that is receiving the API call needs to extract the APINAME and pass the APIPARAMS string when calling the cobol module named in "APINAME".

I need to be able to just pass the value of APIPARAMS on, if I have something like the following defined:


01 API-CALL.
03 API-NAME PIC X(30).
03 API-PARAMS PIC X(400).

If I "JSON PARSE" it I end up with binary "junk" in API_PARAMS (API-NAME is spot on) in my cobol program, unless I call if from another cobol program.  When that happens it appears that cobol is putting "\\" in string for APIPARAMS around the quotes and works.  I understand why it should work as its just a quoted string at that point, however my Cpp code uses a web framework so it creating a proper json input as seen above, ie no backslashes.

Question is how do I get the "string" side of API_PARAMS via JSON PARSE or is it not possible?  I know I can define the elements in API_PARAMS and that works, but I don't need to access the params individually, plus they might be different for different calls. In fact my COBOL program is pretty agnostic and just needs to pass the json string (I know its not technically a string, its a map) to the next module it calls.  It then returns the results back to the calling system, essentially its just a simple pass through interface.

I  apologise in advance as I'm not a cobol programmer and haven't done cobol for decades so my terminology etc might be off, but I've googled till I'm running out of the will to live.  Initially I thought it was my cpp program that was sending in duff data but its actually correct, it seems to be how COBOL does or doesn't allow the dumping of the whole of the JSON Map "API_PARAMS".

Thanks in advance


#VisualCOBOL

I'm not sure that JSON Parse can do what you want. Checking into that, and to see if we can suggest any alternatives.

 

I think you described a couple of different concerns:

  • A problem with processing a string passed from C++
  • Your wish to partially process the JSON, and send a subset on to another program

 

To be clear, when you pass a JSON string from your C++ program and then parse it with a fully defined data area (all fields declared to match the particular passed JSON string) is that working for you? What errors do you get when you run the JSON PARSE? I believe you can use the "WITH DETAIL" option on the JSON PARSE to get errors displayed at runtime.


I'm not sure that JSON Parse can do what you want. Checking into that, and to see if we can suggest any alternatives.

 

I think you described a couple of different concerns:

  • A problem with processing a string passed from C++
  • Your wish to partially process the JSON, and send a subset on to another program

 

To be clear, when you pass a JSON string from your C++ program and then parse it with a fully defined data area (all fields declared to match the particular passed JSON string) is that working for you? What errors do you get when you run the JSON PARSE? I believe you can use the "WITH DETAIL" option on the JSON PARSE to get errors displayed at runtime.

I've been advised that JSON PARSE as currently implemented does not support the functionality you described (variably defined JSON strings).

There might be some options for getting something like that to work with additional coding. If you'd like to pursue that, I would recommend creating a Support Case, you can ask that it be assigned to Blair McDonald.


I've been advised that JSON PARSE as currently implemented does not support the functionality you described (variably defined JSON strings).

There might be some options for getting something like that to work with additional coding. If you'd like to pursue that, I would recommend creating a Support Case, you can ask that it be assigned to Blair McDonald.

The Knowledge Base article below shows a possible way to handle the type of JSON strings (with variable number and format of parameters) that was described in this discussion.

Can I use JSON PARSE when JSON strings have variable parameters? (microfocus.com)