Page 1 of 1

json-parse with inner double quote

PostPosted: Thu Jun 20, 2013 11:56 am
by kosh
Hi.

json-parse cannot handle JSON data with inner double quote chars.

Code: Select all
> (setf data [text]{"foo": ["bar", "\"baz\""]}[/text])
"{\"foo\": [\"bar\", \"\\\"baz\\\"\"]}"
> (json-parse data)
nil
> (json-error)
("invalid JSON array format" 19)


This problem doesn't occur in previous json module.

Code: Select all
> (module "json.lsp")
MAIN
> (json2expr data)
(("foo" ("bar" "\"baz\"")))


P.S. Is json module no longer available?
Documentation page is alive. but download link is 404.
http://www.newlisp.org/code/modules/json.lsp.html

Re: json-parse with inner double quote

PostPosted: Thu Jun 20, 2013 3:16 pm
by Lutz
Thanks Kosh, now fixed here:

http://www.newlisp.org/downloads/develo ... nprogress/

Code: Select all
newLISP v.10.5.2 64-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h

> (setf data [text]{"foo": ["bar", "\"baz\""]}[/text])
"{\"foo\": [\"bar\", \"\\\"baz\\\"\"]}"
>  (json-parse data)
(("foo" ("bar" "\"baz\"")))
>


Ps: also restored the source for the old json.lsp

Re: json-parse with inner double quote

PostPosted: Fri Jun 28, 2013 12:39 pm
by kosh
Thanks Lutz.

Code: Select all
newLISP v.10.5.2 32-bit on Win32 IPv4/6 UTF-8 libffi, options: newlisp -h

> (json-parse [text]{"a backslash":"\\"}[/text])
(("a backslash" "\\\\"))


This retun value is maybe (("a backslash" "\\"))

Regards.

Re: json-parse with inner double quote

PostPosted: Fri Jun 28, 2013 2:37 pm
by Lutz
Thanks Kosh, I fixed the escaped back slash:

Code: Select all
> (json-parse [text]{"a backslash":"\\"}[/text])
(("a backslash" "\\"))


... for cases in your other post, where json-parse lets pass certain misformed content, json-parse will stay as it is:

http://www.newlisp.org/downloads/develo ... nprogress/