json.lsp

Module index

source download

Module: json.lsp

JSON to S-expression parser (obsololete because native since 10.4.6)

Author: L.M. March 2010, Jan 2011, Ted Walther 2011
Version: v. 0.1 - initial release
Version: v. 0.21 - bug fixes for long string objects and empty token lists
Version: v. 0.30 - now processes backslashed chars as of JSON spec


The module defines a function jason2expr translating JSON into Lisp S-expressions.

§

json2expr

syntax: (json2expr str-json-data)
Params: The JSON formatted data string.
Only one JSON expression should be passed to the function.

return: The S-expression

Example:
(setq json-text [text]
 {
      "firstName": "John",
      "lastName": "Smith",
      "address": {
          "streetAddress": "21 2nd Street",
          "city": "New York",
          "state": "NY",
          "postalCode": "10021"
      },
      "phoneNumbers": [
          { "type": "home", "number": "212 555-1234" },
          { "type": "fax", "number": "646 555-4567" }
      ]
  }
 [/text])

 ; parse json-text to s-expression
 (json2expr json-text) =>

 (("firstName" "John") 
  ("lastName" "Smith") 
  ("address" (
     ("streetAddress" "21 2nd Street") 
     ("city" "New York") 
     ("state" "NY") 
     ("postalCode" "10021")))
  ("phoneNumbers" (
     (("type" "home") ("number" "212 555-1234")) 
     (("type" "fax") ("number" "646 555-4567")))))



- ∂ -

generated with newLISP  and newLISPdoc