B
BobNoobGuy
Guest
How can I READ-JSON this (below) into temp table :
This is what I have written so far. Right now the export stream dOut1 does not produce anything. My guess is that I don't have all the table specify... DO I need to define all json node like: Args, Data, Files, Headers, Origin and URL? Thank you for your help
Thank you
Continue reading...
Code:
{
"args": {
},
"data": "{\"name\":\"morpheus11\",\"job\":\"leader1221\"}",
"files": {
},
"form": {
},
"headers": {
"Accept": "application\/json",
"Content-Length": "40",
"Content-Type": "application\/json",
"Host": "httpbin.org",
"User-Agent": "OpenEdge-HttpClient\/0.4.0 (UNIX\/64) OpenEdge\/99.2.99.0.9999 Lib-ABLSockets\/0.5.0",
"X-Amzn-Trace-Id": "Root=1-9999998e-0e281713363302e331999999"
},
"json": {
"job": "leader1221",
"name": "morpheus11"
},
"origin": "888.53.150.88",
"url": "https:\/\/httpbin.org\/post"
}
This is what I have written so far. Right now the export stream dOut1 does not produce anything. My guess is that I don't have all the table specify... DO I need to define all json node like: Args, Data, Files, Headers, Origin and URL? Thank you for your help
Code:
def temp-table tt serialize-name 'json'
field job as char
field name as char.
def dataset args for tt.
def var dURL as char no-undo init "https://httpbin.org/post".
def var dRequest as IHttpRequest no-undo.
def var dResponse as IHttpResponse no-undo.
def var dClient as IHttpClient no-undo.
def var dRequestResp as longchar no-undo.
def var dJson as JsonObject no-undo. /* used by outbound Json and the return inbound Json */
dClient = ClientBuilder:Build():Client.
dJson = new JsonObject() .
dJson:Add("name","morpheus11").
dJson:Add("job","leader1221").
dRequest = RequestBuilder:Post(dURL,dJson)
:ContentType('application/json')
:AcceptJson()
:Request.
dResponse = dClient:Execute(dRequest).
if dResponse:StatusCode <> 200 then do:
message subst("dResponse:StatusCode = &1", dResponse:StatusCode).
end.
else do:
dJson = cast(dResponse:Entity, JsonObject).
dJson:Write(dRequestResp, true).
dataset args:read-json("longchar",dRequestResp).
for each tt on error undo, return error on stop undo, return error:
export stream dOut1 delimiter "|"
tt.
end.
output stream dOut1 close.
end.
Thank you
Continue reading...