News for hackers. Stuff that matters.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by nly on Sunday December 10, 2017 @11:18AM (#15892035)
That's great, but most JSON libraries don't give you that level of access... they just decode in to a bunch of nested maps/dicts consisting of your languages native data types. So one day you swap out your JSON library and the behaviour of your application silently changes.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by gregmac on Sunday December 10, 2017 @12:34PM (#15892423)
This is what unit testing is for. Test the methods that validate and return your expected object structures. This catches other things like a structure changing (as simple as a property being modified), ensuring you can handle malformed input (even if it's valid JSON) and any other data validation rules you have.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by colanderman on Sunday December 10, 2017 @12:21PM (#15892345)
Use a better JSON library :)

(There are competent JSON implementations, though they're few and far between. PostgreSQL's is the only good example I can point to off the top of my head.)

Re:Son: A minimal subset of JSON for machine-to-machine comm... by chrismorgan on Sunday December 10, 2017 @12:40PM (#15892455)
Here’s what Rust’s `json` crate does for the `Number` type: https://docs.rs/json/0.11.12/json/number/struct.Number.html

It stores it as positive, mantissa and exponent, allowing you to pull it apart in that way if you need to. Meanwhile, normal usage is via JsonValue (https://docs.rs/json/0.11.12/json/enum.JsonValue.html) which allows you to attempt to convert it into an f64, i32, u8, &c. as you desire, returning `None` if it doesn’t fit inside that type (e.g. -7 won’t go into an i32, 576 won’t go into a u8).

By what’s being talked about here, that looks to be a competent JSON implementation.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by colanderman on Sunday December 10, 2017 @03:07PM (#15893235)
Wonderful. Good to know that about Rust, I haven't used it but everything I read about it looks good. Yes that is exactly the approach I meant (and a similar mechanism to that used by my own C++ JSON library I use for side projects).
Re:Son: A minimal subset of JSON for machine-to-machine comm... by LambdaComplex on Sunday December 10, 2017 @01:33PM (#15892736)
Doesn't most of the Rust ecosystem use serde though?
Re:Son: A minimal subset of JSON for machine-to-machine comm... by steveklabnik on Sunday December 10, 2017 @02:09PM (#15892926)
It looks like serde-json does the same: https://docs.serde.rs/serde_json/struct.Number.html
Re:Son: A minimal subset of JSON for machine-to-machine comm... by chrismorgan on Sunday December 10, 2017 @10:20PM (#15894922)
Well, not the same; it eagerly interprets it as PosInt(u64), NegInt(i64) or Float(f64) rather than storing the mantissa and exponent. This is enough for JavaScript compatibility (its Number type being essentially a 64-bit float), but it’s not quite as flexible as the json crate’s approach.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by jandrese on Sunday December 10, 2017 @12:04PM (#15892265)
Shouldn't they return a list of warnings/errors on the parse? Just blindly accepting a machine parse of some random input data is how you crash programs with bad input.