JSON transformation

A web framework in newLISP
Post Reply
denis
Posts: 20
Joined: Wed Apr 27, 2011 12:19 pm
Location: Petsamo, Murmansk, RU

JSON transformation

Post 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?

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

Re: JSON transformation

Post 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.

denis
Posts: 20
Joined: Wed Apr 27, 2011 12:19 pm
Location: Petsamo, Murmansk, RU

Re: JSON transformation

Post by denis »

Thanks, cormullion!

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

Ryon
Posts: 248
Joined: Thu Sep 26, 2002 12:57 am

Re: JSON transformation

Post 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.

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

Re: JSON transformation

Post by cormullion »

Good job!

Post Reply