JsonSerialize() and JsonDeserialize() wrappers

There are two helper methods that provide single line of code JSON serialization and deserialization.

Note that these are standalone UDF() functions rather than class methods:

JsonSerialize()

lcJson = JsonSerialize(loObjectOrValue, llFormat)

llFormat determines whether the JSON is indented.

JsonDeserialize()

loObject = JsonSerialize(lcJson)

Example

Here's an example of how to use these

DO wwJsonSerializer

*** Create an object
loObject = CREATEOBJECT("Empty")
ADDPROPERTY(loobject, "Name", "Rick")
ADDPROPERTY(loObject, "Company", "West Wind")
ADDPROPERTY(loObject, "Entered", DATETIME())

*** Serialize to JSON
lcJson = JsonSerialize(loObject, .t.)
? lcJson

*** Deserialize from JSON into an Object
loObject = JsonDeserialize(lcJson)
? loObject.Name
? loObject.Company
? loObject.Entered

© West Wind Technologies, 1996-2022 • Updated: 03/15/21
Comment or report problem with topic