wwJsonSerializer::MapPropertyName

Maps a JSON property name to a new name. This can be useful if you created JSON from a FoxPro object, but the JSON needs a property name that FoxPro's property naming limitations don't allow for.

You can create JSON property names with spaces, dots, dashes or any other special characters or names that start with a number, all of which are not supported in FoxPro. You can basically map a FoxPro property name to any other string value all of which are supported in string delimited JSON map property names.

Unlike PropertyNameOverrides which can only transform case of a property, the MapPropertyName() method allows you to map property names to any string value including those that FoxPro properties would not otherwise support.

o.MapPropertyName(@lcJson, lcOriginal,lcNewName)

Return Value

(preferrably pass by reference and ignore) - otherwise returns updated JSON string

Parameters

@lcJson
The JSON document as a string. Preferrably pass by reference so the value is updated in place. Otherwise the method can return the new JSON string.

lcOriginalName
The original name to replace in the JSON string

lcNewName
The name to change it to.

Example

The following example creates JSON properties with spaces:

loSer = CREATEOBJECT("wwJsonSerializer")
loObj = CREATEOBJECT("EMPTY")
ADDPROPERTY(loObj,"LastName","Strahl")
ADDPROPERTY(loObj,"FirstName","Rick")

*** Create initial JSON
*** { "lastname": "Strahl", "firstname": "Rick" }
lcJson = loSer.Serialize(loObj)

*** Now update the property names
loSer.MapPropertyName(@lcJson, "lastName","Last Name")
loSer.MapPropertyName(@lcJson, "firstName","First Name")

*** { "Last Name": "Strahl", "First Name": "Rick" }
? lcJson

See also:

Class wwJsonSerializer | wwJsonSerializer::PropertyNameOverrides

© West Wind Technologies, 2023 • Updated: 01/31/23
Comment or report problem with topic