Problem with (json-parse) false/nil
Posted: Mon Dec 29, 2014 11:40 pm
JSON understands only "false", but Lisp understands only "nil" and they are not the same.
false should translate from JSON to nil in Lisp...
Create a file called test.json:
In other words, false is not nil!
From the newLisp manual:
false should translate from JSON to nil in Lisp...
Create a file called test.json:
Code: Select all
{
"name": false,
"age": 32,
"employed": true,
"address": {
"street": "701 First Ave.",
"city": "Sunnyvale, CA 95125",
"country": "United States"
} }
Code: Select all
(setf json_text (read-file "test.json"))
setf json_lisp (json-parse json_text))
; the result below should be (name nil) and not (name false)
(("name" false) ("age" 32) ("employed" true) ("address"
(("street" "701 First Ave.")
("city" "Sunnyvale, CA 95125")
("country" "United States"))) )
Code: Select all
(lookup "name" json_lisp)
; false
(nil? (lookup "name" json_lisp))
; nil
In newLISP, nil and true represent both the symbols and the Boolean values false and true. Depending on their context, nil and true are treated differently. The following examples use nil, but they can be applied to true by simply reversing the logic.
Evaluation of nil yields a Boolean false and is treated as such inside flow control expressions such as if, unless, while, until, and not. Likewise, evaluating true yields true.