JSON Engine documentation

Started by michaelgreer, August 06, 2024, 03:58:10 PM

Previous topic - Next topic

michaelgreer

Back in March Mike King wrote:
March 28, 2024, 12:28:19 PM
Last Edit: March 28, 2024, 02:58:32 PM by Mike King
Another simple solution, which will work when using older PxPlus, is to predefine the JSON structure then load the values:

For example, we can preload the numeric JSON elements with zero values.  Only the numeric values need be declared.

->x$="{'Balance':0}"
->dim load json$=x$

[/color]
The above will create the array json$ with add the element Balance marked as numeric.  Now you can define the various values you need.

->json$["Name"]="Mike King"
->json$["Addr"]="123 Main St"
->json$["Balance"]="123.45"
->json$["Email"]="mike.king@bbsysco.com"

When the Array is converted back to JSON the Numeric indicator for Balance is remembered.

->print dim(list edit json$)
{
  "Addr":"123 Main St",
  "Balance":123.45,
  "Email":"mike.king@bbsysco.com",
  "Name":"Mike King"
}

I have never seen the notation in blue described anywhere. Indeed, learning to use the superb json handling is hit or miss (or ask on this forum).  Is there a comprehensive description of how to use the json engine?

Devon Austen

The relevant documentation can be found as part of the DIM directive documentation and the DIM function documentation here are some direct links:

https://manual.pvxplus.com?directives/dim.htm#load

https://manual.pvxplus.com?functions/dim.htm#json
Principal Software Engineer for PVX Plus Technologies LTD.