Sotiris,
Yes, the XPRIM_JSON.Writer object can be reused within a list.
Are you wanting the output Json to be just simple json string, or are you wanting the output to be an array?
Not sure if this is what you are looking for, but here is a simple sample I tested to work.
Writer defined in the S/M:
DEFINE_COM Class(#XPRIM_JsonWriter) Name(#Writer)
I defined a work list and loaded test data:
Code: Select all
* define work list
DEF_LIST Name(#wrkList) Fields(#std_code #STD_DESC) Counter(#STD_INT) Type(*Working) Entrys(*Max)
* Build list
#STD_CODE := 'A'
#STD_DESC := 'Apples'
ADD_ENTRY To_List(#wrkList)
#STD_CODE := *blank
#STD_DESC := *blank
#STD_CODE := 'B'
#STD_DESC := 'Bananas'
ADD_ENTRY To_List(#wrkList)
#STD_CODE := *blank
#STD_DESC := *blank
#STD_CODE := 'C'
#STD_DESC := 'Cherries'
ADD_ENTRY To_List(#wrkList)
#STD_CODE := *blank
#STD_DESC := *blank
Then build the writer object with the data from the work list:
Code: Select all
* Begin root
#Writer.BeginObject
* begin list objectname
#Writer.BeginObject Name('outputListAsJson')
SELECTLIST Named(#wrkList)
#Writer.WriteString Name(#STD_CODE) Value(#STD_DESC)
ENDSELECT
* End list data
#Writer.EndObject
* end root
#Writer.EndObject
This produced the Json output as such:
{
"outputListAsJson": {
"A": "Apples",
"B": "Bananas",
"C": "Cherries"
}
}