JSON transformation

A web framework in newLISP

JSON transformation

Postby denis » Fri Jun 03, 2011 3:17 pm

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?
denis
 
Posts: 20
Joined: Wed Apr 27, 2011 12:19 pm
Location: Petsamo, Murmansk, RU

Re: JSON transformation

Postby cormullion » Sun Jun 05, 2011 6:50 pm

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.
cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W

Re: JSON transformation

Postby denis » Mon Jun 06, 2011 10:41 pm

Thanks, cormullion!

It turned to be trivial, like I suspected! Lists, not quoted lists! Shame on me! :-)
denis
 
Posts: 20
Joined: Wed Apr 27, 2011 12:19 pm
Location: Petsamo, Murmansk, RU

Re: JSON transformation

Postby Ryon » Tue Jun 07, 2011 3:29 pm

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.
Ryon
 
Posts: 248
Joined: Thu Sep 26, 2002 12:57 am

Re: JSON transformation

Postby cormullion » Tue Jun 07, 2011 4:23 pm

Good job!
cormullion
 
Posts: 2037
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W


Return to Dragonfly

Who is online

Users browsing this forum: No registered users and 1 guest

cron