Feature update: JSON encoding and decoding
The JSON data format allows for structured data to be easily stored and exchanged. For example, in a Real Estate app, the data related to a given property could look like this:
{
"propertyID": "12345",
"price": 350000,
"location": {
"city": "Anytown",
"state": "CA"
},
"details": {
"type": "Single Family Home",
"beds": 3,
"baths": 2
},
"features": [
"garage",
"fireplace"
]
}
In GuidedTrack, we use an association to structure data in a similar manner:
>> propertyData = {"propertyID" -> "12345", "price" -> 350000, "location" -> {"city" -> "Anytown", "state" -> "CA"}, "details" -> { "type" -> "Single Family Home", "beds" -> 3, "baths" -> 2}, "features" -> ["garage", "fireplace"]}
Or, in a more visual way:
>> propertyData = {}
>> propertyData["propertyID"] = "12345"
>> propertyData["price"] = 350000
>> propertyData["location"] = {"city" -> "Anytown", "state" -> "CA"}
>> propertyData["details"] = { "type" -> "Single Family Home", "beds" -> 3, "baths" -> 2}
>> propertyData["features"] = ["garage", "fireplace"]
To convert a GuidedTrack association into a JSON string, such as when using it as input for a ChatGPT conversation, use the function encode
with the “JSON” scheme:
>>propertyData_jsonString = propertyData.encode("JSON")
Similarly, to convert a JSON string back into an association, use the decode
function with the same scheme:
>>propertyData = propertyData_jsonString.decode("JSON")
To summarize:
Function | Input Type | Output Type |
.encode(“JSON”) | association | text |
.decode(“JSON”) | text | association |