CLOSE ALL
CLEAR ALL
CLEAR

SET PROCEDURE TO qdfoxJSON
JSONStart()

?"JSON Test #4"
?"Version " + JSON.Version
?
?"THIS TEST SHOWS HOW TO USE SCHEMAS TO SIMULATE DATA STRUCTURES"
?
?"Declaring schema..."
JSON.declareSchema("Person","{firstName:string,lastName:string,Age:numeric,DOB:date}")
??"Done!!"
?
?"Creating test object..." 

LOCAL o
o = JSONObject("schema:Person")
o.firstName = "Victor"
o.lastName = "Espina"
o.Age = 42
o.DOB = {^1970/11/18}

??"Done!"

?"Serializing object..."
LOCAL cJSON
cJSON = o.ToJSON()
?cJSON

?
?"Deserializing object..."
RELEASE o
o = JSONObject(cJSON)
??"Done!!"

?
?"Validating object's schema..."
IF o.Is("Person")
 ??"Its a " + o.Schema
ELSE 
 ??"Its NOT a Person"
ENDIF

?
?"Accessing object contents..."
?"Name"
?"",o.firstName, o.lastName
?"Age"
?"",o.Age
?"DOB"
?"",o.dob
?"Schema"
?"",o.Schema
 
?
?"Test completed"
?
?"For more information, read initial comments at qdfoxJSON.PRG file"

RETURN


DEFINE CLASS Person AS Custom
 FirstName = ""
 LastName = ""
 Age = 0
 DOB = {}
ENDDEFINE