[vim] jsondecode() parses incorrect JSON (#593)

21 views
Skip to first unread message

Nikolai Aleksandrovich Pavlov

unread,
Jan 24, 2016, 10:40:23 AM1/24/16
to vim/vim

With Vim 7.4.1165 try jsondecode('[,]'). This will produce [v:none], but this string is not a correct JSON. jsondecode('[1,]') produces [1], but JSON spec does not allow trailing commas. jsondecode('{1: 1,}') produces {'1': 1}, but JSON spec does not allow non-string keys or trailing comma.


Reply to this email directly or view it on GitHub.

Nikolai Aleksandrovich Pavlov

unread,
Jan 24, 2016, 10:41:50 AM1/24/16
to vim/vim

Also jsondecode('1.') produces 1.0, but JSON spec does not allow omitting number after decimal point.

Bram Moolenaar

unread,
Jan 24, 2016, 11:54:10 AM1/24/16
to vim/vim

Nikolai Pavlov wrote:

> With Vim 7.4.1165 try `jsondecode('[,]')`. This will produce

> `[v:none]`, but this string is not a correct JSON.
> `jsondecode('[1,]')` produces `[1]`, but JSON spec does not allow
> trailing commas. `jsondecode('{1: 1,}')` produces `{'1': 1}`, but JSON
> spec does not allow non-string keys or trailing comma.

jsondecode() allows for a bit more than the standard. I'll update the
documentation. This takes it a bit in the direction of what JavaScript
eval() does.

--
Have you heard about the new Beowulf cluster? It's so fast, it executes
an infinite loop in 6 seconds.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Jun 28, 2016, 4:32:00 PM6/28/16
to vim/vim

Closed #593.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Reply all
Reply to author
Forward
0 new messages