Create JSON

Posted by dvega on 22-Mar-2018 13:40

Hi,

Please could you help me to generate this JSON file, my doubt is about the two first fields, the other are records of a temp table is not problem.

{
"exito": true,
"message": "",

......

I put the two temp table on a Dataset, but I got the follwing.

{"dsDirEnvio": {

  "": [

    {

      "exito": true,

      "message": "Correcto"

    }

  ],

  "data": [

 

Thank you in advanced.

 

DIEGO FERNANDO VEGA

{
"exito": true,
"message": "",
"data": [{
"iddireccion": "000989vcj 010",
"nombre": "testing",
"numero": "",
"condado": "LOS ANGELES",
"comp_env": "DIA SIG",
"nombre_cd": "BEVERLY HILLS",
"colonia": "Colonia referencia",
"folio": 10,
"complemento": "Complemento referencia",
"etiqueta": "testing",
"ciudad": "Beverly",
"cp": "12210",
"estado": "CA",
"tipo": "ALTERNA",
"clv_pais": "USA",
"correo": "correo@gmail.com",
"direccion": "conocida",
"telefono": "1234567890"
},
{
"iddireccion": "000515vcj0aa",
"nombre": "test2",
"numero": "",
"condado": "HARRIS",
"comp_env": "DIA SIG",
"nombre_cd": "HOUSTON",
"colonia": "Colonia referencia",
"folio": 11,
"complemento": "Complemento referencia",
"etiqueta": "test2",
"ciudad": "BOSTON",
"cp": "11007",
"estado": "TX",
"tipo": "ALTERNA",
"clv_pais": "USA",
"correo": "correo@test.com",
"direccion": "test 2",
"telefono": "1212121212"
}]
}

Posted by Simon L. Prinsloo on 23-Mar-2018 03:25

DEF VAR oJson AS JsonObject NO-UNDO.

DEF VAR oData AS JsonArray NO-UNDO.

oJson = NEW JsonObject().

oData = NEW JsonArray().

TEMP-TABLE ttData:WRITE-JSON("JsonArray",oData).

oJson:Add("exito", TRUE).

oJson:Add("message", "").

oJson:Add("data", oData).

oJson:WriteFile("file.json").

All Replies

Posted by goo on 22-Mar-2018 14:32

Use the jsonObject and jsonArray classes instead, build it yourself instead of turning to dataset. I found that easier to get the result I needed.
 
//Geir Otto
 

Posted by dvega on 22-Mar-2018 15:52

Hi Geir,

I wil to do.

Thank you.

DIEGO FERNANDO VEGA

Posted by Simon L. Prinsloo on 23-Mar-2018 03:25

DEF VAR oJson AS JsonObject NO-UNDO.

DEF VAR oData AS JsonArray NO-UNDO.

oJson = NEW JsonObject().

oData = NEW JsonArray().

TEMP-TABLE ttData:WRITE-JSON("JsonArray",oData).

oJson:Add("exito", TRUE).

oJson:Add("message", "").

oJson:Add("data", oData).

oJson:WriteFile("file.json").

Posted by dvega on 23-Mar-2018 08:18

Hi Simon,

Nice.

Thank you.

DIEGO FERNANDO VEGA

This thread is closed