PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: Mike Hatfield on August 22, 2019, 11:45:24 PM

Title: JSON files
Post by: Mike Hatfield on August 22, 2019, 11:45:24 PM
Hi All,

When I create JSON files from PxPlus each element terminates with comma+0A.
I note that most JASON files we process from other sources are a continuous stream of data with only a comma between elements.
If I parse the PxPlus file at https://jsonformatter.org/ is validates OK.

Is this correct for PxPlus or should I be doing something to eliminate the 0A ?

SMPRICE_JSON:
CLEAR SMPRICEJSON${ALL}
LET SMPRICEJSON$["Price Date"]=""
LET SMPRICEJSON$["Products.1.Inventory_SKU"]=""
LET SMPRICEJSON$["Products.1.List_Price"]=""

LET SMPRICEJSON$["Price Date"]=DYMD$
FOR I=1 TO 5
READ RECORD (ICM1)ICM1$
LET SMPRICEJSON$["Products."+STR(I)+".SKU"]=ICM1.STOCK_CODE$
LET SMPRICEJSON$["Products."+STR(I)+".Price"]=STR(ICM1.PRICES[1])
NEXT I
LET SMPRICE$=DIM(LIST EDIT SMPRICEJSON${ALL})
LET JSONFILE$="/hit/temp/czapijson.json";
       ERASE JSONFILE$,ERR=*PROCEED;
       SERIAL JSONFILE$;
       OPEN (HFN,ISZ=LEN(SMPRICE$))JSONFILE$;
       WRITE RECORD (LFO)SMPRICE$;
       CLOSE (LFO)

Thanks
Title: Re: JSON files
Post by: koenv on August 23, 2019, 03:58:37 AM
Replace
LET SMPRICE$=DIM(LIST EDIT SMPRICEJSON${ALL})
with
LET SMPRICE$=DIM(LIST SMPRICEJSON${ALL})