West Wind Internet and Client Tools
wwJsonSerializer DeserializeJson and Serialize functions
Gravatar is a globally recognized avatar based on your email address. wwJsonSerializer DeserializeJson and Serialize functions
  Neil
  All
  Nov 19, 2019 @ 05:46am

Hi When using the Serialize and DeserializeJson methods with CallService the JSON string is converted to lowercase (version 7.0). This causes me a problem with Mailchimp API calls as the Audience Merge Fields are case sensitive, and if not sent (POST/PATCH) in uppercase I can't update member contact details. The response from Mailchimp is also converted to lowercase adding to the confusion.

Is there an easy way to stop the conversion to lowercase, or is the only other option to use wwDynamic class with .addProp __PropertyNameOverrides?

I took a look at wwDynamic, but could not see how a new objects reference becomes the PropertyNameOverrides values even after passing the object to wwjsonserializer serialize method, at what point should they be back in uppercase?, and as MailChimp "merge_fields" requires a child collection how do I use correctly addProp to place an object in the parent object?

Many Thanks

Gravatar is a globally recognized avatar based on your email address. re: wwJsonSerializer DeserializeJson and Serialize functions
  Rick Strahl
  Neil
  Nov 19, 2019 @ 12:01pm

Yes this is a known issue. FoxPro cannot figure out proper property names, its reflection features only provide single case values. wwJsonSerializer defaults to lowercase for everything given there isn't case information available.

However, you can override property names via the PropertyNameOverrides property. Provide a comma delimited list of all the properties (including nested ones) that need to be translated to camelCase (or any other case for that matter).

do wwJsonSerializer

loObject = CREATEOBJECT("Empty")
ADDPROPERTY(loObject,"Name","Rick")
ADDPROPERTY(loObject, "LastName", "Strahl")
ADDPROPERTY(loObject,"Company","West Wind")
ADDPROPERTY(loObject,"Entered",DATETIME())

loSer = CREATEOBJECT("wwJsonSerializer")

*** Produces: {"company":"West Wind","entered":"2012-02-27T23:31:49Z",
***            "name":"Rick", "lastname":"Strahl" }
*** Properties are always rendered lower case
? loSer.Serialize(loObject)

*** Make sure these properties render in proper case
loSer.PropertyNameOverrides = "Name,Company,Entered, lastName"

*** Produces: {"Company":"West Wind","Entered":"2012-02-27T23:31:49Z","Name":"Rick","lastName": "Strahl"}
*** specified properties are overridden
? loSer.Serialize(loObject)

Note you only have to override properties that need to change. If properties are single value lowercase then the override isn't needed - only for mixed case property names.

Deserialization is case insensitive so that shouldn't matter.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: wwJsonSerializer DeserializeJson and Serialize functions
  Neil
  Neil
  Nov 20, 2019 @ 05:26am

Now works Thanks Rick

© 1996-2019