Main Board > Programming

JSON from Array with numeric and string



I'm wondering if there was a way I could "force" a json value to be a numeric when the Array is set to string.   I have a case where I need to send the data in a specific format for the end user (not pvx) who uses variable types.

So my data is all sent as if they were string, but I'd like one specific value to be without quotation mark, so as a numeric value.

I thought that maybe there was a prefix I could put before the value so that PVX would recognize it as a numeric for the end result of :

"value": 1,

instead of

"value": "1",

Loren Doornek:
Use the "with num" option for JSON to specify which values are numeric.  Below is an example.

print dim(list edit arr${all} with num("numeric"))


Loren Doornek:
Here is a better example, which uses a comma-delimited list of the JSON elements that should be numeric.

0010 BEGIN
0020 LET arr$["string"]="123"
0030 LET arr$["numeric"]="123",withnum$+="numeric,"
0040 LET arr$[""]="456"
0050 LET arr$[""]="456",withnum$+=","
0060 PRINT "Withnum$= ",withnum$
0070 PRINT DIM(LIST EDIT arr${ALL} WITH NUM(withnum$))


Withnum$= numeric,,


[0] Message Index

Go to full version