Post #: 81
Post type: Blog post
Date: 2013-01-30 16:28:47.000
Author: Rocket Man
JSON stands for the JavaScript Object Notation, and it's used by lots of applications because it's much more compact than the bulky XML format. It's also suspiciously similar to LISP lists, which isn't that surprising considering that JavaScript was originally written as a LISP interpreter.
The basic format is something like this:
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
I've written a function in Rockets that converts this notation into a native newLISP list. Basically all I've done is replace { with ( and [ with (, then removed colons, commas, and other extraneous syntax. I ran into a small problem with very large text strings, because newLISP's internal list evaluator doesn't like them and returns a "string token too long" error. To fix this, I put [text] and [/text] in place of everything that had quotes, which tells newLISP's internal evaluator to treat it as a long string of text. Using (read-eval) I convert this long string of long strings back into a list, and all the [text] and [/text] goes away and you have a normal list!
The function is called
(convert-json-to-list) and it's included in Rockets. I'm already finding it useful for my new project.
View this post in the forums
Views: 6868