There is a good module for converting between JSON and newLISP data structures. It's clean and very elegant. But it is unfortunately not usable for converting bigger JSON structures to newLISP because it takes a lot of time and just crashes.
My thought was: hey, JSON looks very much like LISP. Ok, it has [ and }, but they can be replaces with regular parens? If I just replace those braces with regular parens and remove comma and colon, why wouldn't newLISP be able to parse it? So here's a very quick and dirty hack that implements most of JSON. It lacks support for objects/dictionaries (they are treated just like arrays for now) and I should probably check that numbers are correct.
Code: Select all
(set 'jsstr (trim (read-file "/home/km/conf/gcontacts.json")))
(set 'lspstr "")
(dostring (c jsstr)
(let (x (char c))
(if
(= x "[") (write-buffer lspstr "(")
(= x "{") (write-buffer lspstr "(")
(= x "}") (write-buffer lspstr ")")
(= x "]") (write-buffer lspstr ")")
(= x ":") (write-buffer lspstr " ")
(= x ",") (write-buffer lspstr " ")
(write-buffer lspstr x))))
; TODO: support for dicts, check that numbers are fine
(set 'result (eval-string (string "'" lspstr)))
(set-ref-all 'false result nil)
(set-ref-all 'null result nil)
;(println result)
Code: Select all
-rw-r----- 1 km km 898372 Nov 12 02:20 /home/km/conf/gcontacts.json
Code: Select all
0.890u 0.022s 0:00.93 97.8% 313+854k 0+0io 0pf+0w
Code: Select all
ERR: call or result stack overflow : = <805ADC0>
called from user defined function Json:read-string
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from user defined function Json:tokenize
called from
18.257u 8.775s 0:28.32 95.4% 314+896k 0+0io 0pf+0w
Kirill