# Friday, December 19, 2008
JSON Class Update
Since my initial post regarding this class, work has continued improving it. A number of fixes and enhancement can be found in the latest version...

  • Fixes to parse method - There was a problem with brace matching for "{}" and "[]" when nested in certain ways.
  • Fixes to UseUTCDatetime functionality - rules are now as follows:
    • UseUTCDateTime = .F. && Datetimes will stringify including Local offset from UTC
    • UseUTCDateTime = .T. && Datetimes will stringify as UTC equivalent for Local
    • Parse() && will always return Local equivalent
  • Fixes to GetTimezoneOffset method - now respects Standard/Daylight boundaries of datetimes
  • Fixed Stringify - cursors are serialized to valid JSON now
  • Added KeyForCursor property - this allows a JSON key to be specified for identifying cursors (defaulted to "VFPData")
  • Enhanced Stringify and Parse methods - they now handle the VFP Collection class with aplomb
  • Added KeyForItems property - when serializing Collections, the key for the contained JSON object's array property can be defined (defaulted to "items")
  • Renamed DateSerializationType property - it is now ParseDateType
  • Enhanced Parse - JSON class will now (optionally) respect Class and ClassLibrary properties if they exist in a JSON object being deserialized (see ParseRespectClass property). This means that if you Stringify() a VFP Form and then Parse() the JSON (with ParseRespectClass = .T.) you will get a Form object back rather than an Empty object with the same properties as the Form.
I would consider the JSON class production-ready at this point. This doesn't mean that bugs won't be found in the future, but it has been hammered on enough that I wouldn't hesitate to use it in a production application.

Visual FoxPro Now Listed
I got in touch with Douglas Crockford and was able to get Visual FoxPro listed on JSON.org with a link to my initial post. I appreciate Douglas Crockford taking the time out of his busy schedule to list Visual FoxPro on the JSON site.

Special Thank You
Nearly all of the fixes and enhancements provided in this version of the JSON class were made possible by the help and prodding I received from Frank Dietrich of Berlin. He is an extremely bright fellow. Implementing the Timezone and Daylight vs. Standard stuff drove us both to the brink. I sincerely doubt I could have done it without his help.

Download the JSON class library (approx. 59 KB)

The download contains the JSON class in both VCX and PRG format. They are the same. Use whichever one you prefer.
Friday, December 19, 2008 9:43:59 AM (GMT Standard Time, UTC+00:00)  #    Comments [3]
Sunday, January 18, 2009 7:05:11 AM (GMT Standard Time, UTC+00:00)
Great class, Craig! I've been using it in production with no issues at all.

It's clearly documented that if one wants to serialize an array, one needs to pass it by reference.

HOWEVER now I have a situation where I have an array of rows as a property of an object.

How can I serialize an array member as part of serializing the object itself? I tried passing the "@array" property as part of the tvReplacer property but that doesn't seem to work.

Any ideas? Thanks!

Test code:

SET PROCEDURE TO Json ADDITIVE

o= CREATEOBJECT("Empty")
ADDPROPERTY(o, "Myarray[3]")
o.MyArray[1]="Serialize"
o.MyArray[2]="all"
o.MyArray[3]="of me!"
oJSON= CREATEOBJECT("Json")

CLEAR

? oJSON.Stringify(o) && {"myarray": "Serialize"}

* ?oJSON.Stringify(o,"@MyArray") && Crash

DIMENSION aReplacer[1]
aReplacer[1]="@myarray"
? oJSON.Stringify(o,@aReplacer) && {}
Sunday, March 08, 2009 7:31:01 PM (GMT Standard Time, UTC+00:00)
Thanks for reporting this Steven. Sorry it has taken me so long to get to this.

The problem is in the PROTECTED PROCEDURE serializeobject around line 919 the code should read something like the following...

m.lcPropertyFullname = "m.toObject." + m.lcKey
IF TYPE(m.lcPropertyFullname) != "U" && members like ACTIVECONTROL may not be an object
IF TYPE(m.lcPropertyFullname, 1) != "A"
m.lvMemberValue = GETPEM(m.toObject, m.lcKey)
ELSE
RELEASE lvMemberValue
=ACOPY(&lcPropertyFullname, lvMemberValue)
ENDIF
ELSE
m.lvMemberValue = NULL
ENDIF
Sunday, March 08, 2009 7:41:17 PM (GMT Standard Time, UTC+00:00)
I've uploaded an updated version of the JSON library. Redownload it and the problem should be solved.
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview

 

Archive

<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910