Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Export partial JSon to a response message

Question
Kurro Lopez · Feb 25, 2021

Export partial JSon to a response message

Hi all,

I have a API operation that is calling to a external process. The answer is a big json but I only want a pice of the full content.

My first attempt is:

.....
// The code of prepare the request is omitted.
set tSC = ..Adapter.SendFormDataArray(.tHttpResponse,"POST",tHttpRequest,,,tURL)
if $$$ISERR(tSC) $$$ThrowStatus(tSC)
// Get the response directly
set response = ""
while (tHttpResponse.Data.AtEnd = 0) {
    set response = respuesta_tHttpResponse.Data.Read()
}
// Convert Json to generic object, get the node returnValue.data and convert to JSon again
set objJson = ##class(%DynamicObject).%FromJSON(response)
set jsonReturnValue = objJson.returnValue.data.%ToJSON()
$$$TRACE("Content ReturnValue: "_jsonReturnValue)
do ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(jsonReturnValue,"MyMsg.PartialJson",.pResponse)
......

The JSon response is:

{
  "result": "OK",
  "returnValue": {
    "code": "0",
    "message": "Info",
    "data": {
      "ext_customer_id": "123456789",
      "customer_name": "FRANCISCO",
      "customer_surname_1": "LÓPEZ",
      "customer_surname_2": "DE LAS HERAS",
      "passport_id": "123456ZZZ",
      "dob": "1972-02-01",
      "sex": "M",
      "email": "kurro.lopez@gmail.com",
      "active": true
    }
  }
}

and MyMsg.PartialJson class is:

Class MyMsg.PartialJson Extends Ens.Response
{
/// Id del usuario
Property "ext_customer_id" As %String(MAXLEN = 1024);
/// Name customer
Property "customer_name" As %String(MAXLEN = 1024);
/// Surname customer
Property "customer_surname_1" As %String(MAXLEN = 1024);
/// surname 2 customer
Property "customer_surname_2" As %String(MAXLEN = 1024);
/// Passport ID
Property "passport_id" As %String(MAXLEN = 250);
/// Date of birth
Property dob As %String(MAXLEN = 20);
/// Sex
Property sex As %String(MAXLEN = 10);
/// Email
Property email As %String(MAXLEN = 1024);
/// Check if customer is active
Property active As %Boolean;
}

But the pResponse object is empty.

is there any error?

Best regards
Kurro Lopez

#Caché
Product version: Ensemble 2017.1
$ZV: Cache for Windows (x86-64) 2017.2.1 (Build 801_3U) Thu Apr 12 2018 10:02:23 EDT

Source URL:https://community.intersystems.com/post/export-partial-json-response-message