On 23 January 2016, Bram Moolenaar <[email protected]> wrote:
> 
> Lcd wrote:
> 
> > On 23 January 2016, Bram Moolenaar <[email protected]> wrote:
> > > 
> > > Patch 7.4.1154
> > > Problem:    No support for JSON.
> > > Solution:   Add jsonencode() and jsondecode().  Also add v:false, v:true,
> > >             v:null and v:none.
> > [...]
> > 
> >     Very nice, thank you!
> > 
> >     There are still a few rough edges with it though:
> > 
> >     :echo jsondecode('true')
> >     true
> > 
> >     :echo string(jsondecode('true'))
> >     true
> > 
> >     :echo type(jsondecode('true'))
> >     E685: Internal error: f_type()
> >     0
> 
> The new variable type may need to be added in more places.
> I'll fix it for type().  Let me know if you find more.

    Here's another one:

        :echo jsondecode('{') == v:null
        E685: Internal error: get_tv_string_buf()
        E685: Internal error: get_tv_string_buf()
        1

    Implicit type casts from the special values to the other types (or
explicit failures when meaningful conversions are not possible) should
take care of most of the remaining problems.  Doing without those would
be a pain.

    Explicit function casts bool2nr() and null2nr() and friends, and
perhaps also other way around, nr2bool() and friends, would be useful
but probably not absolutely vital.

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

> >     :echo jsondecode('"')
> >     none
> > 
> >     :echo jsondecode('<...most other invalid constructs...>')
> >     none
> 
> There should be more places that produce an error.

    This is still somewhat inconsistent:

        :echo jsondecode('{"a":}')
        E474: Invalid argument
        {'a': none}

    A better way to deal with this might be to find a JSON linter /
validator / pretty printer with tests, and run said tests in Vim.

> >     :echo jsondecode('{-}')
> >     E474: Invalid argument
> >     none
> > 
> >     :echo jsondecode('""')
> >     Vim: Caught deadly signal SEGV
> >     Segmentation fault
> 
> Just fixed that.  Coverity managed to find this one.

    Yes, this works now, thank you.

    /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