[Stackoverflow] [Progress OpenEdge ABL] How to properly build and append a json file from variables

Status
Not open for further replies.
B

Bazilby

Guest
I'm practising programming an application that takes user input and then outputs it to a json file.

I found a how to that explains how to do it. For the sake of length, I'm leaving out the input code and just including the json builder.

ASSIGN
uComp = "testCompany"
uEmail = "testEmail"
uName = "testName"
uAdd = "Additional"

.


DEFINE VARIABLE myObj AS JsonObject NO-UNDO.
DEFINE VARIABLE myData AS JsonObject NO-UNDO.
DEFINE VARIABLE dataParams AS JsonObject NO-UNDO.
DEFINE VARIABLE lResult AS LONGCHAR NO-UNDO
VIEW-AS EDITOR LARGE SIZE 60 BY 16.
DEFINE VARIABLE lJArray AS JsonArray NO-UNDO.
DEFINE VARIABLE lAnotherArray AS JsonArray NO-UNDO.

OUTPUT TO "output path.json".


myObj = NEW JsonObject().
dataParams = NEW JsonObject().



myObj:Add("id", "01").

dataParams:Add("Company_name", uComp).
dataParams:Add("uEmail", uEmail).
dataParams:add("uName", uName).
dataParams:add("AddInfo", uAdd).


lJArray = NEW JsonArray().
lJArray:Add(dataParams).


myObj:Add("data", lJArray).


myObj:Write(lResult, TRUE).




DISPLAY lResult.


That part works fine, but my output is like so:

lResult-----------------------------------------------------

{
"id": "01",
"data": [
{
"Company_name": "testCompany",
"uEmail": "testEmail",
"uName": "testName",
"AddInfo": "Additional"
}
]
}



how do I prevent the

lResult-----------

from being added to the file.

Secondly, I want to add additional information to the file when the code runs again so that the output will become.

{
"id": "01",
"data": [
{
"Company_name": "testCompany",
"uEmail": "testEmail",
"uName": "testName",
"AddInfo": "Additional"
},
{
"Company_name": "testCompany",
"uEmail": "testEmail",
"uName": "testName",
"AddInfo": "Additional"
}
]
}



What is the correct way to target a point in the file and add additional objects?

I though it might be something along the lines of an


property.

Continue reading...
 
Status
Not open for further replies.
Top