News for hackers. Stuff that matters.
Re:Building a high performance JSON parser by Semaphor on Sunday June 28, 2020 @10:06AM (#23668769)
> E.g., an object's "foobar" field is always an array of int, and won't suddenly become a string from one invocation to the next.

If only… I had to figure out how to deserialize a JSON API where a field could be: a) an object X, b) an array of X, or c) a string (mapping to X.Y)

Re:Building a high performance JSON parser by chrismorgan on Sunday June 28, 2020 @12:37PM (#23669984)
That doesn’t need to be a problem. In Rust, the most popular thing in this space is Serde, with the serde_json crate. It can cope with such things just fine; define a data type that is capable of representing all the possibilities (perhaps as simple as an enum with a variant for each style, or perhaps it normalises them into one), and then… well, you probably have to write a visitor to help deserialise, which isn’t trivial, especially when you’re used to just deriving those things and so you’re not so familiar with Serde internals. But it’s possible. https://serde.rs/string-or-struct.html gives one example. The length of the example may be daunting, but it’s actually not too bad.
Re:Building a high performance JSON parser by Semaphor on Monday June 29, 2020 @03:39AM (#23675380)
It was C#. I ended up writing a custom converter that converted all 3 cases into X[]