Re: Empty key in JSON
2016-01-26 16:29 GMT+03:00 Bram Moolenaar: > > Yukihiro Nakadaira wrote: > >> :echo jsondecode('{"":"x"}') >> E713: Cannot use empty key for Dictionary >> >> Will Vim allow empty key? > > Hmm, if you take the standard literally I suppose it allows for an empty > key. In practice it's an indication something went wrong. > > Why are you asking, do you see a practical application for it? In addition to diffing there is also caching: imagine function that compiles PCRE regex into Vim regex (or fallback implementation for glob2regpat() for older Vim versions). Using dictionaries for caching is natural and empty pattern is also the valid one. I do not see why this restriction exists in first place, most of dictionary implementations allow empty strings simply because *not* allowing it requires additional length checks which will not be written without a good reason. > > The standard also allows for duplicate names, even though in practice > that doesn't work. So even though it's valid JSON, it doesn't mean it's > a valid value after converting from JSON to Vim types. Standard states this is implementation-defined (though in place of one sentence and using this exact term they have written a whole paragraph with this meaning). In any case “internal error” is not something that should be reported in this case, documentation explicitly states that internal error is a bug. > > So the error is actually correct, it's not saying the JSON is invalid, > it's saying the result in Vim types is invalid. > > -- > hundred-and-one symptoms of being an internet addict: > 40. You tell the cab driver you live at > http://123.elm.street/house/bluetrim.html > 41. You actually try that 123.elm.street address. > > /// Bram Moolenaar -- b...@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/// > > -- > -- > You received this message from the "vim_dev" maillist. > Do not top-post! Type your reply below the text you are replying to. > For more information, visit http://www.vim.org/maillist.php > > --- > You received this message because you are subscribed to the Google Groups > "vim_dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to vim_dev+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Empty key in JSON
:echo jsondecode('{"":"x"}') E713: Cannot use empty key for Dictionary Will Vim allow empty key? -- Yukihiro Nakadaira - yukihiro.nakada...@gmail.com -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Empty key in JSON
Yukihiro Nakadaira wrote: > :echo jsondecode('{"":"x"}') > E713: Cannot use empty key for Dictionary > > Will Vim allow empty key? Hmm, if you take the standard literally I suppose it allows for an empty key. In practice it's an indication something went wrong. Why are you asking, do you see a practical application for it? The standard also allows for duplicate names, even though in practice that doesn't work. So even though it's valid JSON, it doesn't mean it's a valid value after converting from JSON to Vim types. So the error is actually correct, it's not saying the JSON is invalid, it's saying the result in Vim types is invalid. -- hundred-and-one symptoms of being an internet addict: 40. You tell the cab driver you live at http://123.elm.street/house/bluetrim.html 41. You actually try that 123.elm.street address. /// Bram Moolenaar -- b...@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/// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Empty key in JSON
On Tue, Jan 26, 2016 at 10:29 PM, Bram Moolenaarwrote: > > Yukihiro Nakadaira wrote: > > > :echo jsondecode('{"":"x"}') > > E713: Cannot use empty key for Dictionary > > > > Will Vim allow empty key? > > Hmm, if you take the standard literally I suppose it allows for an empty > key. In practice it's an indication something went wrong. > > Why are you asking, do you see a practical application for it? > I don't know practical example in JSON. In Vim script, counting line is a possible example. let d = {} for line in getline(1, '$') let d[line] = get(d, line, 0) + 1 endfor for line in getline(1, '$') if d[line] == 1 do something else do something endif endfor Patience diff algorithm uses such a method, for example. https://github.com/ynkdir/vim-diff/blob/master/autoload/diff/patience.vim Although, there is a workaround like d['x'.line] = ... > The standard also allows for duplicate names, even though in practice > that doesn't work. So even though it's valid JSON, it doesn't mean it's > a valid value after converting from JSON to Vim types. > > So the error is actually correct, it's not saying the JSON is invalid, > it's saying the result in Vim types is invalid. > I see. -- Yukihiro Nakadaira - yukihiro.nakada...@gmail.com -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.