News for hackers. Stuff that matters.
Re:Parsing JSON Is a Minefield (2018) by exabrial on Saturday August 17, 2019 @12:48PM (#20724853)
I miss the days of strongly typed schemas. It's much easier to fail gracefully.
Re:Parsing JSON Is a Minefield (2018) by Spivak on Saturday August 17, 2019 @12:51PM (#20724872)
Throw your support behind https://json-schema.org it's a great effort.
Re:Parsing JSON Is a Minefield (2018) by rapsey on Saturday August 17, 2019 @12:58PM (#20724917)
Or use something sane like protocol buffers
Re:Parsing JSON Is a Minefield (2018) by nyxxie on Saturday August 17, 2019 @02:36PM (#20725510)
I've used protobufs in the past and I REALLY want to use them now, but the human readable aspect of json has always kept me coming back.

If I want to perform some rough tests of an endpoint during development, all I need to do is compose the json request and fire it off using curl. The response then comes back in a human readable format I can parse straight from the terminal. Boom, simple test conducted in less than 1 minute. I don't even need to think about it.

Compare that to protobufs; I need to create a custom client or unit test that'll compose and fire off the request I want to test, then I need to write a bunch of code that will introspect the contents of the response so I can pick out the details. Huge time loss, concentration ruined since I need to actually think about the process, I'd rather just take the extra latency that using json will incur.

This skips past all of the other advantages json has over binary serialization protocols, like quickly being able to parse requests while debugging issues, infinite client language support, ease of sharing breaking requests to help devs reproduce problems, not needing to add an extra compilation step to my deployments and packages, etc.

Re:Parsing JSON Is a Minefield (2018) by q3k on Saturday August 17, 2019 @09:40PM (#20727676)
> If I want to perform some rough tests of an endpoint during development, all I need to do is compose the json request and fire it off using curl. The response then comes back in a human readable format I can parse straight from the terminal. Boom, simple test conducted in less than 1 minute. I don't even need to think about it.

https://github.com/fullstorydev/grpcurl

Re:Parsing JSON Is a Minefield (2018) by jakear on Saturday August 17, 2019 @01:05PM (#20724953)
A problem we're finding with those is the massive runtime dependency you get trying to include protobuf in browser.
Re:Parsing JSON Is a Minefield (2018) by rapsey on Saturday August 17, 2019 @01:20PM (#20725033)
In that case json can be used as an addon. An optional input/output that a number of protobuff libraries support.

One should keep schema in protocol buffers and encourage its use for all but browsers.

Re:Parsing JSON Is a Minefield (2018) by izacus on Saturday August 17, 2019 @01:22PM (#20725041)
The minimal parser seems to be 6.5kb, which seems significantly smaller than most of other JS dependencies apps use these days.
Re:Parsing JSON Is a Minefield (2018) by jakear on Saturday August 17, 2019 @01:35PM (#20725140)
We make dependencies, so staying small is more important for us than for end-users.
Re:Parsing JSON Is a Minefield (2018) by nh2 on Saturday August 17, 2019 @01:09PM (#20724970)
Protobuf crashes with data larger than 2GB (json does not).

This severely limits its usefulness, unless you want to put workarounds of this shortcoming into your application.

Other protobuf-like things like capnproto don't have that restriction, because they don't use 32 bit integers for sizes.

Re:Parsing JSON Is a Minefield (2018) by kentonv on Saturday August 17, 2019 @03:21PM (#20725778)
You really don't want to put >2GB in a single protobuf (or JSON object). That would imply that in order to extract any one bit of data in that 2GB, you have to parse the entire 2GB. If you have that much data, you want to break it up into smaller chunks and put them in a database or at least a RecordIO.

Cap'n Proto is different, since it's zero-copy and random-access. You can in fact read one bit of data out of a large file in O(1) time by mmap()ing it and using the data structure in-place.

Hence, it makes sense for Cap'n Proto to support much larger messages, but it never made sense for Protobuf to try.

Incidentally the 32-bit limitation on Protobuf is an implementation issue, not fundamental to the format. It's likely some Protobuf implementations do not have this limitation.

(Disclosure: I'm the author of Protobuf v2 and Cap'n Proto.)

Re:Parsing JSON Is a Minefield (2018) by yongjik on Saturday August 17, 2019 @01:24PM (#20725054)
Generally speaking, if you have 2GB of data, why would you want it inside a protobuf, or worse, json? You clearly aren't going to open it in a text editor or send it over ajax - just put the bulk of data as a separate binary blob, and your code won't have to scan 2GB to find the end of a string.
Re:Parsing JSON Is a Minefield (2018) by rapsey on Saturday August 17, 2019 @01:17PM (#20725014)
Not even remotely is it a severe restriction. Very few need that.
Re:Parsing JSON Is a Minefield (2018) by hrktb on Saturday August 17, 2019 @02:18PM (#20725411)
While it’s a valid point, there are many workarounds.

Also even in json, splitting documents in smaller chunks (ndjson for instance) is the standard practice to avoid having to parse it all in one go.

Re:Parsing JSON Is a Minefield (2018) by bcrosby95 on Saturday August 17, 2019 @01:05PM (#20724949)
How would I pad my resume if I didn't keep reinventing the same wheels over and over?
Re:Parsing JSON Is a Minefield (2018) by Pfhreak on Saturday August 17, 2019 @01:24PM (#20725061)
I can understand if protocol buffers had some technical issue that you disagreed with. Or if you had a preference for a different solution because of some reason.

But this comment seems needlessly cynical and doesn't actually offer any rebuttal to the parent's point. I find technical discussions of these sorts of things interesting and a great way for new people to learn about the tradeoffs, maybe you could offer a reasoned opinion on why not use protocol buffers?

Re:Parsing JSON Is a Minefield (2018) by yongjik on Saturday August 17, 2019 @01:30PM (#20725106)
I think GP is making fun of people who do not use protobufs and instead try newer, less proven ones...
Re:Parsing JSON Is a Minefield (2018) by EdwardDiego on Sunday August 18, 2019 @12:07AM (#20728178)
I have a love/hate relationship with JSON schema. I hate the documentation, or significant lack thereof. But I do love how business rules about relationships between fields can be expressed in the schema - e.g., if typeId is 7, then the cost field must be populated.

With things like Avro or GPB you still need to validate that the relationship holds true separately.

Re:Parsing JSON Is a Minefield (2018) by gumby on Saturday August 17, 2019 @04:04PM (#20726000)
Isn't that just lipstick on a pig? Why not use something pre-existing and well defined?
Re:Parsing JSON Is a Minefield (2018) by nighthawk648 on Sunday August 18, 2019 @09:21AM (#20729982)
What is your opinion of the swagger spec + definition?
Re:Parsing JSON Is a Minefield (2018) by izacus on Saturday August 17, 2019 @01:17PM (#20725015)
A lot of companies still use typed messages like Protocol Buffers which make this a signficantly smaller issue. Especially since the message format was designed to be portable.
Re:Parsing JSON Is a Minefield (2018) by jasonhansel on Sunday August 18, 2019 @12:59AM (#20728329)
A question: just like JSON's syntax was based on JavaScript, could we create a JSON schema syntax based on TypeScript? So the schema would essentially be a TypeScript type annotation.
Re:Parsing JSON Is a Minefield (2018) by sorokod on Saturday August 17, 2019 @01:40PM (#20725172)
JSON schema validation requires a JSON parser so not sure how this helps in the context.