How to eliminate escape characters from JSON in IWS REST API?
Kelly Cookson <KCookson-EAwJ3jYHSpVWk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.systems.as400.web |
|---|---|
| Message-ID | <SN6PR02MB41575D81FF82556341FA23ABAA949@SN6PR02MB4157.namprd02.prod.outlook.com> |
How do I get rid of escape characters in JSON output when calling a stored procedure from an IWS REST API?
1. The problem is not caused by the stored procedure. When I call the stored procedure from ACS Run SQL Scripts, the JSON contains no escape characters.
call myLib.myStrdProc('GETDATES',' ',?);
The JSON from Run SQL Scripts looks like this:
Output Parameter #3 (JSON_OUT_PARM) = {"MYFILE":[{"Begin Date":20200101,
"Close Date":20200126},{"Begin Date":20210101,"Close Date":20210131}]}
2. The problem occurs when I call the stored procedure from An IWS REST API procedure. The JSON contains escape characters.
The SQL call in the REST API procedure is the same:
call myLib.myStrdProc ('GETDATES',' ',?)
The JSON looks like this:
"JSON_OUT_PARM": "{\"MYFILE\":[{\"Begin Date\":20200101,\"Close Date\":20200126},
{\"Begin Date\":20210101,\"Close Date\":20210131}]}"
The relevant code snippets from the stored procedure are:
-- PROCEDURE DEFINITION
CREATE OR REPLACE PROCEDURE MYSTRDPROC
(IN ACTION_PARM CHAR(30),
IN JSON_IN_PARM CLOB(1M) DEFAULT NULL,
INOUT JSON_OUT_PARM CLOB(1M) DEFAULT NULL)
RESULT SETS 1
LANGUAGE SQL
SET OPTION DBGVIEW = *SOURCE
WHEN ACTION_PARM = 'GETDATES' THEN
SELECT JSON_OBJECT('MYFILE':
JSON_ARRAYAGG(
JSON_OBJECT(
'Begin Date' : MYBEGDT,
'Close Date' : MYCLSDT
RETURNING CLOB(1M))))
INTO JSON_OUT_PARM
FROM MYLIB.MYFILE
WHERE (MYYEAR=2020 OR MYYEAR=2021)
AND MYPRD=1;
Thanks,
Kelly Cookson
Senior Software Engineer II
Dot Foods, Inc.
1-217-773-4486 ext. 12676
www.dotfoods.com<http://www.dotfoods.com>
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/web400.