On Tue, Jan 26, 2016 at 10:29 PM, Bram Moolenaar <b...@moolenaar.net> wrote:

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

Raspunde prin e-mail lui