On 24 January 2016, Bram Moolenaar <[email protected]> wrote:
>
> Lcd wrote:
>
> > > [...]
> > > > >     Actually, since you added two more values for type(), it
> > > > > would make sense to make Bool and Null standard types, Vim
> > > > > citizens with full rights.  But some careful consideration
> > > > > would be needed for the interaction with the other types, so
> > > > > that they can also be used for other purposes, unrelated to
> > > > > JSON.
> > > >
> > > > The thing is that the only valid values are what we have now.
> > > > Giving those types a name doesn't really help.
> > > >
> > > > >     The alternative would be to make jsondecode() return
> > > > > only standard Vim values (that is, true --> 1, false --> 0,
> > > > > null --> ''), and leave v:<special> only for encoding.  Less
> > > > > powerful, but a lot simpler, and a lot more robust.
> > > >
> > > > Then you can't tell the difference between decoding a zero or
> > > > "false".  This drops information that might be important.  I'm
> > > > sure this will be a problem at a later time.
> > >
> > >     Yes, but now we have the worst of the two worlds: types that
> > > aren't quite types, and values that aren't quite values.  They'll
> > > break things eventually.  Actually, Nikolai Aleksandrovich Pavlov
> > > has a few examples when they do.  F.i. eval(string(var)) is no
> > > longer guaranteed to be the same as var.
> > [...]
> >
> >     One more thing: adjusting the result of jsondecode() to contain
> > only "standard" values involves deep traversal, which is not
> > trivial.  Actually, it's pretty hard to get right.
>
> Example?

    Anything nested would do:

:echo jsondecode('[{"a":true, "b":false}, null, {"foo": true, "bar": true, 
"baz": null}]')
[{'a': true, 'b': false}, null, {'foo': true, 'baz': null, 'bar': true}]

    Replacing all true, false, and null with "plain" 0, 1, and '' means
traversing the leaves of this.

    /lcd

-- 
-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui