# [RFC] jsond

- Thread: https://externals.io/message/80374
- Original archive: https://news-web.php.net/php.internals/80374
- Started by Jakub Zelenka on 2015-01-11T17:27:35+00:00
- Messages: 14
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #80374 — Jakub Zelenka — 2015-01-11T17:27:35+00:00

URL: https://externals.io/message/80374#80374

Hi,

This rfc about replacing json with jsond is under discussion.

https://wiki.php.net/rfc/jsond

I have finally done some benchmarks. You can find a link in the RFC.

It's been extensively tested for the last few months and there is just one
BC that I'm aware of.

The new parser accepts only float number that conforms to RFC 7159 . This
is also not consistent between decoding float number that are and are not
in the array/object ( there are two conversion rules). The following
formats are rejected:

1. parsed at the top level: 07, 0xff, .1, -.1
2. parser by JSON_Parser: [1.], [1.e1]

I feel that this was a bug in the new parser and we must conform to RFC
7159 !

Cheers

Jakub

---

## #80375 — Leigh — 2015-01-11T17:56:43+00:00

URL: https://externals.io/message/80374#80375 · In reply to: #80374

>
> I feel that this was a bug in the new parser and we must conform to RFC
> 7159 !
>

I agree. +1

---

## #80376 — Jakub Zelenka — 2015-01-11T18:06:26+00:00

URL: https://externals.io/message/80374#80376 · In reply to: #80374

>
> I feel that this was a bug in the new parser and we must conform to RFC
> 7159 !
>

Typo! I meant of course that it was a bug in the old parser (the current
json extension)... :)

---

## #80377 — Paul Dragoonis — 2015-01-11T19:07:19+00:00

URL: https://externals.io/message/80374#80377 · In reply to: #80374

>
> Hi,
>
> This rfc about replacing json with jsond is under discussion.
>
> https://wiki.php.net/rfc/jsond
>
> I have finally done some benchmarks. You can find a link in the RFC.
>
> It's been extensively tested for the last few months and there is just one
> BC that I'm aware of.
>
> The new parser accepts only float number that conforms to RFC 7159 . This
> is also not consistent between decoding float number that are and are not
> in the array/object ( there are two conversion rules). The following
> formats are rejected:
>
> 1. parsed at the top level: 07, 0xff, .1, -.1
> 2. parser by JSON_Parser: [1.], [1.e1]
>
> I feel that this was a bug in the new parser and we must conform to RFC
> 7159 !

I was just thinking about your jsond work just yesterday actually.

I feel if we need to make a minor BC break to get this in, then go with it
for PHP 7.

I do think that if it's possible for you to detect when users supply this
invalid float input that you would throw an informative exception to help
people with the transition over to PHP7.

What's the rest of the team's thoughts on this ?

>
> Cheers
>
> Jakub

---

## #80378 — Jakub Zelenka — 2015-01-11T20:10:58+00:00

URL: https://externals.io/message/80374#80378 · In reply to: #80377

Hi,


>
> I feel if we need to make a minor BC break to get this in, then go with it
> for PHP 7.
>
Yes, it's proposed only for PHP 7 as declared in the RFC


> I do think that if it's possible for you to detect when users supply this
> invalid float input that you would throw an informative exception to help
> people with the transition over to PHP7.
>

Let's first show an example and make clear what the whole thing:
http://3v4l.org/2D72Q

As you can see, the first type (07, 0xff, .1 and -.1) examples are really
inconsistent and give a different results if there are in the array (error)
or as a scalar. This seems like an obvious bug.

The type 2 is consistent. The only problem is that such number format does
not conform to RFC 7159 where the number is specified in
https://tools.ietf.org/html/rfc7159#section-6 :

    number = [ minus ] int [ frac ] [ exp ]
    frac = decimal-point 1*DIGIT

As you can see there is required a digit after decimal point... In this
case we have a non conforming parser which is not right IMHO.

About the special error messages. I could add a new error codes to identify
these problem. However I am not sure that the current json error codes
gives a useful information that would help with migration. I plan to look
on error reporting later and create a different RFC if this one gets in. I
have got an already implementation for bison locations in my testing
scanner and parser ( you can see some logic in
https://github.com/bukka/jso/blob/master/src/jso_parser.y#L160 ) that I
used as an inspiration for jsond. The idea is to provide full reporting
that includes location where the error is (line and column) and possibly
text sample near to the error as well deeper identification of the error.
It's not just this where we can give more info about the cause of the
error. There is still some work and testing that will need to be done
before I propose it however.

Cheers

Jakub

---

## #80380 — Andrea Faulds — 2015-01-11T21:19:44+00:00

URL: https://externals.io/message/80374#80380 · In reply to: #80378

Hey Jakub,

> 
> 
> Let's first show an example and make clear what the whole thing:
> http://3v4l.org/2D72Q
> 
> As you can see, the first type (07, 0xff, .1 and -.1) examples are really
> inconsistent and give a different results if there are in the array (error)
> or as a scalar. This seems like an obvious bug.
> 
> The type 2 is consistent. The only problem is that such number format does
> not conform to RFC 7159 where the number is specified in
> https://tools.ietf.org/html/rfc7159#section-6 :
> 
>    number = [ minus ] int [ frac ] [ exp ]
>    frac = decimal-point 1*DIGIT
> 
> As you can see there is required a digit after decimal point... In this
> case we have a non conforming parser which is not right IMHO.

It’s not even valid according to the train-track diagrams on json.org:

    http://json.org/number.gif

Thanks for your work on this.
--
Andrea Faulds
http://ajf.me/

---

## #80405 — Xinchen Hui — 2015-01-12T03:01:13+00:00

URL: https://externals.io/message/80374#80405 · In reply to: #80374

Hey:



> Hi,
>
> This rfc about replacing json with jsond is under discussion.
>
> https://wiki.php.net/rfc/jsond
>
> I have finally done some benchmarks. You can find a link in the RFC.
>
> It's been extensively tested for the last few months and there is just one
> BC that I'm aware of.
>
> The new parser accepts only float number that conforms to RFC 7159 . This
> is also not consistent between decoding float number that are and are not
> in the array/object ( there are two conversion rules). The following
> formats are rejected:
>
> 1. parsed at the top level: 07, 0xff, .1, -.1
> 2. parser by JSON_Parser: [1.], [1.e1]
>
does master of josnd already works with PHP7?

I was plan to benchmark the performance with wordpress,

but seems it still not compileable with PHP7?

thanks
> I feel that this was a bug in the new parser and we must conform to RFC
> 7159 !
>
> Cheers
>
> Jakub



-- 
Xinchen Hui
@Laruence
http://www.laruence.com/

---

## #80409 — Remi Collet — 2015-01-12T05:59:39+00:00

URL: https://externals.io/message/80374#80409 · In reply to: #80374

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Le 11/01/2015 18:27, Jakub Zelenka a écrit :
> Hi,
> 
> This rfc about replacing json with jsond is under discussion.
> 
> https://wiki.php.net/rfc/jsond
> 

+1


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlSzYssACgkQYUppBSnxahjnzwCgtLMbdlQ196QhzwObD5lDdyk8
8XcAoNhmwtT9LGCteUYREHX3d6J+YPec
=DPvv
-----END PGP SIGNATURE

---

## #80415 — Jakub Zelenka — 2015-01-12T10:24:02+00:00

URL: https://externals.io/message/80374#80415 · In reply to: #80405

Hey



>
> does master of josnd already works with PHP7?
>
>
There is a patch against PHP master that replaces current json ext. I
referenced a branch of my PHP fork in RFC.

I have just created a PR as well to make it a bit easier if you or others
want to test it and possibly comment on it:

https://github.com/php/php-src/pull/993

The jsond pecl ext does not compile on master. I want to keep as an
alternative json extension for PHP 5 so it needs to compile on 5. There
also are some extra things (e.g. alternative buffer implementation) that I
didn't want to have as a part of this patch. I might make it compilable on
both later but it's not a priority at the moment.

Anyway the patch in the PR should work ok. If not, please let me know and I
will fix it ;)


> I was plan to benchmark the performance with wordpress,
>
>
Great! Please let me know what the results are! ;)

Cheers

Jakub

---

## #80418 — Xinchen Hui — 2015-01-12T13:40:56+00:00

URL: https://externals.io/message/80374#80418 · In reply to: #80415

Hey:


> Hey
>
> 
> > […]
>
> There is a patch against PHP master that replaces current json ext. I
> referenced a branch of my PHP fork in RFC.
>
> I have just created a PR as well to make it a bit easier if you or others
> want to test it and possibly comment on it:
>
> https://github.com/php/php-src/pull/993
>
> The jsond pecl ext does not compile on master. I want to keep as an
> alternative json extension for PHP 5 so it needs to compile on 5. There also
> are some extra things (e.g. alternative buffer implementation) that I didn't
> want to have as a part of this patch. I might make it compilable on both
> later but it's not a priority at the moment.
>
> Anyway the patch in the PR should work ok. If not, please let me know and I
> will fix it ;)
>
> > […]
>
> Great! Please let me know what the results are! ;)

Unfortunately, I don't see performance improvement in wordpress. even
slowdown a bit.

for IRs , it increased IR by 0.05% while run wordpress homepage for 100 times :<

do you think there is some room to be improvement?

thanks
>
> Cheers
>
> Jakub
>



-- 
Xinchen Hui
@Laruence
http://www.laruence.com/

---

## #80421 — Jakub Zelenka — 2015-01-12T18:06:47+00:00

URL: https://externals.io/message/80374#80421 · In reply to: #80418

> Unfortunately, I don't see performance improvement in wordpress. even
> slowdown a bit.
>
> for IRs , it increased IR by 0.05% while run wordpress homepage for 100
> times :<
>
> do you think there is some room to be improvement?
>
> thanks
>

To be honest I expected that there won't be a big difference unless
json_decode is heavily used for bigger json instances.

Anyway the decoder is not fully optimized yet and there definitely is a
room for improvents. It's basically just an initial port for PHP 7. But I
think that it's already good enough to replace the existing json ext as my
benchmarks for instances containing large strings already gives much better
results.

And, of course, it is a PHP licensed parser... :)

Cheers

Jakub

---

## #80431 — Xinchen Hui — 2015-01-13T02:34:02+00:00

URL: https://externals.io/message/80374#80431 · In reply to: #80421

Hey:


> 
> > […]
>
>
> To be honest I expected that there won't be a big difference unless
> json_decode is heavily used for bigger json instances.
>
> Anyway the decoder is not fully optimized yet and there definitely is a room
> for improvents. It's basically just an initial port for PHP 7. But I think
> that it's already good enough to replace the existing json ext as my
> benchmarks for instances containing large strings already gives much better
> results.
>
> And, of course, it is a PHP licensed parser... :)
>
sure, of course, :)

thanks
> Cheers
>
> Jakub
>



-- 
Xinchen Hui
@Laruence
http://www.laruence.com/

---

## #80434 — Pierre Joye — 2015-01-13T02:51:27+00:00

URL: https://externals.io/message/80374#80434 · In reply to: #80431

> Hey:
>
> 
> > […]
> sure, of course, :)

btw, it is important that this point alone justifies this RFC (and us
accepting it as there is no impact on perf and could be better). We
have an issue with the current extension due to the license of the
underlying implementation. Many distros already use alternative
implementations. To solve this problem will make everyone work easier.



-- 
Pierre

@pierrejoye | http://www.libgd.org

---

## #80745 — Jakub Zelenka — 2015-01-18T16:40:09+00:00

URL: https://externals.io/message/80374#80745 · In reply to: #80374

> Hi,
>
> This rfc about replacing json with jsond is under discussion.
>
> https://wiki.php.net/rfc/jsond
>
>
>
I have added a bit more info to the RFC about the BC (the same info that
was discussed here) and also added few more links.

In addition the jsond PR has been updated by merging changes for the
preserving fractional part RFC that has been recently accepted. Thanks to
Juan Basso for sending the patch. ;)

Cheers

Jakub
