A JSONx (spec draft) utility for Gauche.
- Gauche 0.9.6 or later
The XML Namespace URI for JSONx.
Reads and parses the JSON representation from input-port, and returns the result as a JSONx SXML.
Read JSON repeatedly from input-port until it reaches EOF, and returns parsed results as a list of JSONx SXMLs.
Parses the JSON string, and returns the result as a JSONx SXML.
Parses a JSONx SXML into an S-expression.
JSONx datatypes are mapped to Scheme objects as in
parse-json
procedure of rfc.json
module.
Analogous to
json-array-handler
,
json-object-handler
,
and json-special-handler
in rfc.json
module.
Used by parse-jsonx
procedure.
Creates JSONx SXML representation of Scheme object obj.
Scheme objects are mapped to JSONx as in
construct-json
procedure of rfc.json
module.
gosh> (use xml.jsonx)
gosh> (pprint (call-with-input-file "test/data/test.json" parse-json-to-jsonx))
(*TOP*
(http://www.ibm.com/xmlns/prod/2009/jsonx:object
(http://www.ibm.com/xmlns/prod/2009/jsonx:string (|@| (name "name"))
"John Smith")
(http://www.ibm.com/xmlns/prod/2009/jsonx:object
(|@| (name "address"))
(http://www.ibm.com/xmlns/prod/2009/jsonx:string
(|@| (name "streetAddress")) "21 2nd Street")
(http://www.ibm.com/xmlns/prod/2009/jsonx:string (|@| (name "city"))
"New York")
(http://www.ibm.com/xmlns/prod/2009/jsonx:string (|@| (name "state")) "NY")
(http://www.ibm.com/xmlns/prod/2009/jsonx:number (|@| (name "postalCode"))
"10021"))
(http://www.ibm.com/xmlns/prod/2009/jsonx:array (|@| (name "phoneNumbers"))
(http://www.ibm.com/xmlns/prod/2009/jsonx:string "212 555-1111")
(http://www.ibm.com/xmlns/prod/2009/jsonx:string "212 555-2222"))
(http://www.ibm.com/xmlns/prod/2009/jsonx:null (|@| (name "additionalInfo")))
(http://www.ibm.com/xmlns/prod/2009/jsonx:boolean (|@| (name "remote"))
"false")
(http://www.ibm.com/xmlns/prod/2009/jsonx:number (|@| (name "height")) "62.4")
(http://www.ibm.com/xmlns/prod/2009/jsonx:string (|@| (name "ficoScore"))
"> 640")))
gosh> (pprint (construct-jsonx '#(42 #t null (("foo" . #f)))))
(*TOP*
(http://www.ibm.com/xmlns/prod/2009/jsonx:array
(http://www.ibm.com/xmlns/prod/2009/jsonx:number "42")
(http://www.ibm.com/xmlns/prod/2009/jsonx:boolean "true")
(http://www.ibm.com/xmlns/prod/2009/jsonx:null)
(http://www.ibm.com/xmlns/prod/2009/jsonx:object
(http://www.ibm.com/xmlns/prod/2009/jsonx:boolean (|@| (name "foo")) "false")
)))
gosh> (use sxml.sxpath)
gosh> (define t2 (call-with-input-file "test/data/test2.json" parse-json-to-jsonx))
t2
gosh> ((sxpath "//j:object[j:string[@name='City' and . = 'SAN FRANCISCO']]/j:string[@name='Zip']/text()"
`((j . ,jsonx-xmlns)))
t2)
("94107")
MIT