JSON transformation

Started by denis, June 03, 2011, 08:17:26 AM

Previous topic - Next topic

denis

Hello, it's me again about Dragonfly!



While using plugin artfulcode/json.lsp version 2.0 I tried to build a string in json format (lisp->json function). It turned out that I can not pass variables in the expression (or I don't know how to do it).



Example:

(setq var1 "some value")
(Json:lisp->json '(("var1" var1) ("a" 2) ("var2" '(("b" 3) ("c" (+ 2 2))))))
;; will result in -> { "var1": "var1", "a": 2, "var2": { "b": 3, "c": ["+", 2, 2] } }


So I had to change a bit the file json.lsp (wrapping eval around second element of the pair), for it were able to output correct result:



;; -> { "var1": "some value", "a": 2, "var2": { "b": 3, "c": 4 } }


Is it ok, or I again, as newbie to newlisp, missed something trivial?

cormullion

#1
Hi there. I don't think this forum registers in the 'active topics' list ...



I've not used this part of Dragonfly. I wonder if the problem isn't something to do with the quoted list you're using. How is the var1 being expanded, if the entire list is quoted and not evaluated? Nothing inside a quoted list is evaluated.


'(("x" y) ("p" q))

So if you want y and q to be expanded, you'll have to provide a list that has them already evaluated.


(list (list "x" y) (list "p" q))

which at least will get the value of y into the list.

denis

#2
Thanks, cormullion!



It turned to be trivial, like I suspected! Lists, not quoted lists! Shame on me! :-)

Ryon

#3
Quote from: "cormullion"Hi there. I don't think this forum registers in the 'active topics' list ...




Fixed the active topics feature. Thanks for bringing it to my attention.



The Dragonfly forum seems almost lost, doesn't it?



The Dragonfly forum is a sub-board of the "So, what can you actually DO with newLISP?" forum. I've been hoping for more fine newLISP applications to discuss, so that it won't look so lonely.
\"Give me a Kaypro 64 and a dial tone, and I can do anything!\"

cormullion

#4
Good job!