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
I'll also check for missing "}" and "]". The use of v:null was already
fixed.
> 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.
Yes, I made conversion to number and string work. Could give an error,
but that doesn't seem very useful.
> 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 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.
> > > :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.
We can easily add more JSON examples in the test_json.vim test.
> > > :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.
--
The technology involved in making anything invisible is so infinitely
complex that nine hundred and ninety-nine billion, nine hundred and
ninety-nine million, nine hundred and ninety-nine thousand, nine hundred
and ninety-nine times out of a trillion it is much simpler and more
effective just to take the thing away and do without it.
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
/// Bram Moolenaar -- [email protected] -- 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 [email protected].
For more options, visit https://groups.google.com/d/optout.