Class wwJsonSerializer

This class can serialize FoxPro objects, values, collections and cursors to JSON and deserialize JSON strings into FoxPro objects, values or collections. Arrays are supported only as members of objects - all lists should be expressed preferrably as collections.

The serializer supports complex nested structures and can also serialize (but not deserialize) FoxPro tables and cursors by way of a custom string syntax (cursor:AliasName). Objects returned are created dynamically on the fly with all arrays parsed into FoxPro collections.

To serialize:

do wwJsonSerializer
loSer = CREATEOBJECT("wwJsonSerializer")
lcJson = loSer.Serialize(loObject)  && Objects, Values, Collections

You can also serialize cursors:

select * from customers into TCustomers
lcJson = loSer.Serialize("cursor:TCustomers")  && Tables/Cursors

To de-serialize:

loObject = loSer.DeserializeJson(lcJson)  && JSON Objects, Values, Arrays 
? loObject.Value

Class Members

JsonSerialize Helper function to serialize a value or object to JSON.

o.JsonSerialize(lvValue, llFormat, loSerializer)

JsonDeserialize Shortcut function to serialize a value or object to JSON.

o.JsonSerializer(lvValue, llFormat, loSerializer)


Deserializes a JSON string into a FoxPro value, object or wwCollection instance for arrays. This method uses .NET and the JSON.NET library.



Formats a raw JSON string to be indented for easier reading and display.



This method works like FoxPro's ADDPROPERTY() that automatically adds the property name specified to the PropertyNameOverrides so the case is preserved during serialization.



Serializes a FoxPro value to a JSON string. Supports all VFP basic types, most complex objects (as long as there are no circular references), simple arrays and collections and cursors.



If set to .T. assumes that all dates in the data structure passed are UTC dates and the dates are not time adjusted for UTC time.


When .T. causes the output to be pretty formatted with indentations for each object level.


Comma delimited, lower case list of object properties that should not be serialized when serializing objects.


Property name filter applied to properties that are dynamically created by the deserializer. Strips out invalid characters for FoxPro variable names.


Comma delimited list of property names that you like to override on the object to be serialized. Used to force property names into proper case rather than the default lower case only representation.


If .T. trims all string values removing trailing spaces to minimize payload size on the wire.


DO wwJsonSerializer && Load libs

*** Create a complex object
loCust = CREATEOBJECT("Empty")

*** Create a nested object
ADDPROPERTY(loCust,"Address", CREATEOBJECT("Empty"))
ADDPROPERTY(loCust.Address,"Street","32 Kaiea Place")

loSer = CREATEOBJECT("wwJsonSerializer")

*** Serialize into JSON
lcJson =  loSer.Serialize(loCust)

? lcJson
*{"address":{"street":"32 Kaiea Place"},"entered":"2012-05-12T03:55:35Z","name":"Rick"}

*** read back from JSON into an object
loCust2 = loSer.DeserializeJson(lcJson)

? loCust2.Name
? loCust2.Entered
? loCust2.Address.Street
? loCust2.Address.Number

You can also serialize cursors:

select * from customers ;
    into cursor TCustomers ;
    order by company

lcJson = loSer.Serialize("cursor:TCustomers")


Assembly: wwjsonserializer.prg

© West Wind Technologies, 1996-2017 • Updated: 10/09/17
Comment or report problem with topic