Page 1 of 1

JSON transformation

PostPosted: Fri Jun 03, 2011 3:17 pm
by 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:
Code: Select all
(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:

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


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

Re: JSON transformation

PostPosted: Sun Jun 05, 2011 6:50 pm
by cormullion
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.

Code: Select all
'(("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.

Code: Select all
(list (list "x" y) (list "p" q))


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

Re: JSON transformation

PostPosted: Mon Jun 06, 2011 10:41 pm
by denis
Thanks, cormullion!

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

Re: JSON transformation

PostPosted: Tue Jun 07, 2011 3:29 pm
by Ryon
cormullion wrote: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.

Re: JSON transformation

PostPosted: Tue Jun 07, 2011 4:23 pm
by cormullion
Good job!