20 ms·
The Order of the JSON
- tosh 7y agorecent twitter thread referenced in the article: https://twitter.com/therealfitz/status/1161349619659530242?s=20 https://twitter.com/therealfitz/status/1161349619659530242?s...
- pavel_lishin 7y agoFor what it's worth, I do wish it was trivially easy to customize things like error log output, so that I could say that I _always_ want the timestamp first, followed by severity, followed by whatever else. Our logs are annoying to parse when debugging things locally.
- tuananh 7y agoall the modern logging libraries does this now i think. and with app like fluented, we can decorate it with whatever metadata we want (instance name, machine type, container name, etc..)
- Ididntdothis 7y agoThis sounds very familiar. A lot of companies are full of people who have no curiosity and no ability to think for themselves. I have seen it multiple times where someone claimed a change is impossible or takes insane effort. Then you have someone competent look at it and you have a solution in an hour. I think stuff likes this is the real price of not hiring really good people.
- bjoli 7y agoI had the same thing happen to me lately, but I was at the stupid end. I am not a programmer by profession, so it matters very little to me, but I had been struggling to produce a correct solution to a seemingly simple problem (writing a macro to allow definitions in expression context in r6rs scheme). My solution worked but had the side-effect rewriting obviously bad syntax into correct one and not in a good way. I was struggling with how to do it correctly, and then one of the people in the r7rs working group simplified the problem by a very large factor by pointing out to me that I was trying to solve a non-existant problem, because I tried to add definitions to expression contexts where it simply made no sense. In fact, instead of supporting all forms, I could get a better result by just focusing on one of them and add simple wrappers for another 5. It was all quite humbling. Had I taken a step back and actually analyzed the problem I would have come to the same solution, but I immediately tried the, to me, most obvious and also hard-to-get-right solution.
- ajna91 7y agoA very humane telling of a humbling experience.
- trilila 7y agoGreat engineers learn from mistakes, and it seems like you did. Formal training or not, we all make mistakes, but indeed a good approach is to take a step back and analyse _any_ issue or complex problem before implementing it. Sometimes prototyping separate from the main codebase helps.
- tempguy9999 7y agoSuch dumbness is very common with me too, and yet I also call myself a great problem solver, for good reason too. It's not a paradox, it's a matter if excess focus - once I get into a rut I just keep bulldozing[0], but coming to a problem fresh it's often trivial because the rut hasn't formed. I'd say it gets better with experience, and you're probably better than you think - my guess is you don't see your successes as clearly as your failures. I guess you spend so much time on the failures, but if you instantly perceive the right approach to a hard problem and solve it in a shot, well, it wasn't a hard problem, right? A kind of bias of perception. [0]I get the impression that's a bit of a man thing generally
- lacker 7y agoI agree the system described is crazy. However, I find it frequently useful to use ordered JSON as a data format and I think it would be handy if more languages supported it. For one, it makes it a lot easier to write integration tests using a “golden file” of ideal output, because your program that outputs JSON now usually deterministically has one correct output. For two, it lets you hash a json-encoded object deterministically.
- jle 7y agoyou don't need an ordered JSON for this. Just make sure that your equality tests ignore ordering, or that your and hash functions will hash two JSON objects with the same key but different order to the same hash.
- hyperpallium 7y agoOK. I totally prefer ordered JSON, because it is so much easier to eyeball - to visually compare JSON with different ordered keys is quite a lot more difficult (O() complexity?) than if they are in the same order. It also enables diff to help see where the differences are (diagnosis, not just binary identical or not). And, in fact, I do use ordered JSON for comparison in testing, as you describe. However... comparison of JSON as objects (i.e. in memory) is order independent. Hashcode is also order independent (the trick is to sum the elements' hashcodes e.g. https://docs.oracle.com/javase/7/docs/api/java/util/Set.html#hashCode() https://docs.oracle.com/javase/7/docs/api/java/util/Set.html... Diff for ordered JSON is possible using longest common subsequence for trees, but has terrible complexity, and lacks diff's clever optimizations both general and specific to typical input.
- crazygringo 7y ago+1 for all reasons above for ordered JSON, highly convenient in practice. And if it doesn't impact performance significantly, these are all pretty good reasons for JSON outputters to default to sorting objects deterministically by keys, or at least to provide a flag to do so. (Even if there's no canonical sort order between JSON libraries, all that matters is it's deterministic for each library.) BUT... I can't imagine any scenario where you'd want to validate that JSON content was ordered on the input, which is what was enabled in this article. Why does IBM even have that as an option?! Be strict in what you emit and liberal in what you accept, and all that...
- flyinfungi 7y agoSounds like normal life to me. Please give me $$$$
- jrochkind1 7y agoHow were they going to charge him for 9 FTEs for 6 months to uncheck a checkbox?
- duxup 7y agoWrite some software that reordered it probably.
- jeremy_wiebe 7y agoYep. Probably IBM Data Transform Services™️ installed in the cloud plus a custom plugin written to do the ordering. That’s a few folks to deploy and configure the server. A few more for the engineering. Oh and there’s probably a support contract to support and maintain this new “solution”.
- deleted 7y ago[deleted]
- diroussel 7y agoBe cause the checkbox only removed the validation error. Who know what other errors will be encountered when the cobol can't read the incoming messages, which might or might not be in the right order?
- dagw 7y agoPerhaps they didn't know about the checkbox and thought they had to write a custom solution. It could also be that they knew about that really subtle bug that is caused by un-checking that checkbox and thus understood why that didn't actually solve the problem long term if though it looked like a good solution at the time. Or perhaps they're so used to getting away with quoting 6 month for a 6 hour job, it never crossed their mind not to.
- cryptonector 7y agoHa! Stephen Dolan had to add this to jq quite sometime back, making it preserve object key input order on output. And yes, it's infuriating, but it's also somewhat convenient, and yes, there really is software out there that cares about object key order (sigh).
- aflag 7y agoDoesn't anything using jwt depend on a specific order?
- scandinavian 7y agoIt shouldn't, unless you base64 decode the header, then parse it with a library that causes the order to change, encode it again, and then use your own re-encoding to calculate the signature: HMAC-SHA256( b64(reencoded_header) + '.' + b64(payload), secret ) You should really just verify the signature for the provided header + payload in their base64 encoded form.
- m463 7y agoThis makes my head hurt. I wonder if you end up with sorting differences depending on the locale?
- wallyowen 7y agoIt's not sorted, but ordered: The order emitted is the order entered.
- rurban 7y agoWriters should produce sorted maps, readers need to accept unsorted maps. It's a security issue, not just convenience. With unsorted maps the internal hash seed can be exposed, together with timing information. Another famous omission from the specs.
- AgentOrange1234 7y agoI’m no security expert. How is “exposing the hash seed” a problem for the vast majority of applications? What timing information would be leaked and why would that be problem? On the other hand, accepting unsorted maps seems like it could introduce covert channels?
- j88439h84 7y agohttps://bugzilla.redhat.com/show_bug.cgi?id=750555 https://bugzilla.redhat.com/show_bug.cgi?id=750555 This led to hash randomization on by default since Python 3.3.
- AgentOrange1234 7y agoCool. Thanks.
- rurban 7y ago> How is “exposing the hash seed” a problem for the vast majority of applications? They can be DOS'ed. > What timing information would be leaked and why would that be problem? You misunderstood. By 1. leaking the order, and 2. by checking the timing of getting certain keys of a map you do have two independent infos to get at the secret seed. > accepting unsorted maps seems like it could introduce covert channels? A covert channel might be exposed by the sender, if he uses some non-random but unsorted map order. The receiver needs to accept any order. There's no risk in accepting unsorted maps. The only risk at the receiver side is another famous omission from the spec: How to deal with duplicate keys. Accept (overwrite or drop) or reject? All 3 cases can be seen in the wild.
- beached_whale 7y agoI wrote a json serialization/deserialization library for C++ and if you provide the members in the order they are specified in the type you get better performance. It can construct the class without having to bounce the parser back to that location and it is much much more cache friendly.
- couchand 7y agoI also would much rather write code that doesn't quite do what it's supposed to if it's easier to do and I can take an extra day off. However, that's not my job.
- beached_whale 7y agoIt's an interesting problem. So if all the parser does it put them into a variant like structure, sure whatever. But when you go to put them into the reified data types you would be wasting a lot of resources to parse JSON to an intermediary data structure and then request the members. I parse them directly to their final classes. So I was left with a choice and both have a cost. Parse the json in-order of the file and store the concrete type to grab it later, or store the position/size of that part and move to the next constructing them in the order needed. This was cheaper. It will parse the JSON in whatever order, just the performance can be impacted by the data ordering as many parsers are.
- couchand 7y agoIs your parser general-purpose? Is it template-based? Is the performance variance due only to the impact on the processor's cache or are there other factors? Is the code open-source, maybe I could just look myself?
- beached_whale 7y agoIt is template based so that each types JSON parser is statically known and to give the compiler more opportunity to optimize. https://github.com/beached/daw_json_link https://github.com/beached/daw_json_link I haven't had a chance to look at why yet.
- eridius 7y agoThe tweet at the top of the article says > This so far out of the spec it makes my ankles hurt. This is not in fact out of spec. The JSON spec does not define semantics here but instead quite explicitly leaves it up to the JSON processor and data interchange spec for what to do about ordering of objects.
- shortercode 7y agoIf the objects are not guaranteed to be in order, I would always consider them unordered. You could if both the producer and consumer are ordered, but as the OP noted this can cause problems later on and for no good reason. I'd use an array of key-value tuples if I wanted it to be ordered.
- al_form2000 7y agoUh, "no good reason" in this case means "I unchecked the box and nothing bad happened right away" which amounts to shallow analysis, to put it gently.
- Piskvorrr 7y agoThat was a twist ending, indeed. I was expecting a resolution, not "I gave it a good whack and guess what, that fixed it."
- dtech 7y ago> This is not in fact out of spec. The JSON spec does not define semantics [...] for what to do about ordering of objects. What? It is literally on the first page of json.org and section 1 of RFC 7159 [1] > An object is an unordered set of name/value pairs. > An object is an unordered collection of zero or more name/value pairs [1] https://tools.ietf.org/html/rfc7159#section-1 https://tools.ietf.org/html/rfc7159#section-1
- patrickthebold 7y agoThere are multiple standards. https://www.ecma-international.org/publications/standards/Ecma-404.htm https://www.ecma-international.org/publications/standards/Ec... Is more relaxed. >The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs. These are all semantic considerations that may be defined by JSON processors or in specifications defining specific uses of JSON for data interchange. Also it's pretty clear that the keys must have an order going over the wire. And JavaScript objects (which aren't unrelated to JSON have an order now) https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/ https://www.stefanjudis.com/today-i-learned/property-order-i...
- perfunctory 7y ago> How does world not break due to technology more often My own theory is that most (not all) of technology is there to support BS jobs and they are irrelevant for the normal functioning of society. It simply doesn't matter when (most) technology breaks.
- firefoxd 7y agoHa. Creating a layer on top of broken APIs is an thriving business. Every single carrier company has a broken API. That's why companies like aftership exist. One example I struggled with for days recently was USPS. Not only they use xml in the url parameter, the order of the elements also matters. Unfortunately, the order in the documentation is incorrect.
- dnautics 7y agoHell even Amazon's ec2 spec is confusing in some places (the boto python call parameter doesn't always match the restful call, which is less documented, leading to errors in some libraries).
- bullen 7y agoThis is an omission from not only the JSON standard but also the JavaScript language, JavaScript has no map order and the rest is history. The result is that all implementations are broken, f.ex. this is how a tree structure has to be implemented with JSON: http://root.rupy.se/meta/user/task/eelzter/4495378139358454353?sort=2 http://root.rupy.se/meta/user/task/eelzter/44953781393584543... It's inefficient, ugly and just wrong.
- cypressious 7y agoI have written an app for the menu of my university's canteen. The JSON API that I used returned the meals as fields of a document where the order of the fields was the actual display order. It took me a while to even find an implementation of a JSON parser that keeps the order of the fields.
- hobofan 7y agoI would assume that any decent JSON parser has at least the option to keep the order of the fields. Especially for CLI tools that automatically add fields to a JSON file thats usually edited by a user e.g. package.json, I feel that it's absolutely crucial.
- jwilliams 7y ago(I've used both DataPower and COBOL - I've got a healthy respect for robust, long-lived legacy systems). I must admit I was scratching my head on this. The JSON spec might not specify order, but the serialized JSON is ordered by nature. JWT needs it for example (and I'd assume many signature models). Or you might have a caching layer that needs it. Maybe unchecking this causes the legacy backend to get hammered? There are valid non-spec concerns with order. Replies here seem to assume stupidity here. It's a valid reason, but it's not the only one. Equally, the author doesn't ask "why" - why would it take so long, why was that option enabled?
- blattimwind 7y ago> JWT needs it for example (and I'd assume many signature models) You almost never need canonical representations for signing things. I would even say that if you need a canonical representation to sign your things, then that is a design smell of your cryptographic protocol.
- moby_click 7y agoYou don't _need_ canonical representations for signing, but then you can't let go of the representation used for computing the signature. What is the argument against a requirement to only sign canonical data?
- atemerev 7y agoCould you please care to explain more? What is the "design smell", and what is the alternative solution to canonicalization?
- jwilliams 7y agoI didn't mention canonicalization. My point is that serialized JSON is ordered - which I think is exactly the same property you're referring to.
- coldtea 7y agoThat's an implementation detail. Serialized JSON can also be printed, but your systems shouldn't depend that JSON is always ink on paper.
- Someone 7y agoNext installment: how flipping an innocuous switch introduced a subtle bug that was silent for years and cost us millions. You can’t just flip that switch, run ”a client to post the JSON to that instance”, see that test “worked just fine”, and call it a day. The POST might just store it, for later processing to wreak havoc (say by ignoring a value that isn’t in the expected place in the JSON), or only rarely seen JSONs might cause problems, or it might ‘only’ break the yearly run, etc.
- dagw 7y agoYea, that was my big question as well. Was the switch just for that one end point or did he accidentally reconfigure how all the API endpoints in the entire company worked.
- smacktoward 7y agoAlso known as Chesterton’s Fence: https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence https://en.wikipedia.org/wiki/Wikipedia:Chesterton%27s_fence
- dtech 7y agoHow do you justify ever changing anything with that attitude? This change made parsing more lenient which is generally considered fine [1] and made the software actually follow the spec, since it specifies object entries are unordered. [1] https://en.wikipedia.org/wiki/Robustness_principle https://en.wikipedia.org/wiki/Robustness_principle
- tantalor 7y ago> How do you justify ever changing anything By rolling out the change over a period of time to a small sample of users and comparing the experimental effect to a control sample.
- roenxi 7y agoThe target culture would be to justify the change by saying "the reason this was implemented is X but X no longer holds". Anything else is an indicator of change without understanding; which is likely to lead to unforeseen results. The robustness principle is a powerful guideline for interface design; not an excuse to turn off validations that someone else has put in place. If the person who designed the interface wasn't ready for something, principles won't make the software work.
- al_form2000 7y ago"Why would you care what order we were sending the name value pairs for this?" The article makes it sound like it's somehow IBM's fault. However, questions about preserving order in hashes/associative arrays/maps/whatchamacallit span at least thirty years. Some applications of the format even demand it (e.g. ansible uses YAML - a superset of JSON - or even straight JSON for it playbooks; emitting them out of order is not an option). Every time the issue surfaces it elicits a large amount of eye rolling among the cognoscenti. However, I'm a firm believer in the idea that recurring demands from the user base need to be addressed, rather then mocked. The coding community appears to me notably tone deaf on this. 'Course anybody can use <insert suitable technique> to send a JSON map in the desired order, except the parser on the other hand will blissfully disregard it. Or you can devise any ordered solution on both ends, which will leave you outside of the accepted standard and open you up to the situation described in the article (where the requirement may well have been frivolous). I can remember very few - if any - instances of somebody implying that the standard should somehow make room for this kind of scenarios. The standard reply was "use a different format" or "change the requirement". (Somehow remembers me of people asking what can one do to have whitespace-preserving XML, and at least one amusing story about that)
- viraptor 7y agoJson has a perfectly fine order preserving key-value map: [["Key1", "value1"], ["key2", ... You just need to deserialise it into a specific collection on the receiver. It's within standards and there are no weird parser issues.
- al_form2000 7y agoThat's a way. A way that, IMHO, vastly diminishes its expressive power on the reader's side, which I do not consider a very good thing. Most solutions to the issue are of this nature. Consider serialized JSON already has a natural ordering, which is thrown away for some reason (probably parsing convenience).
- viraptor 7y ago
- jmiserez 7y agoI just recently dealt with a JS library that was expecting object properties to be in a certain order ("works" in ES2015 [1]), and that object was loaded via JSON. Was a huge pain getting the object in the required order. [1] https://stackoverflow.com/questions/5525795/does-javascript-guarantee-object-property-order https://stackoverflow.com/questions/5525795/does-javascript-...
- mirimir 7y ago> Much of the system was so old that it was hard to find anyone who knew how it actually worked, and it’s maintenance had been outsourced to some of the typical IT outsourcing companies of the time. Some years ago, I worked on an antitrust case involving a firm that had outsourced relevant systems. Multiple times, to different IT firms. And there was literally nobody left who knew how they worked. After considerable negotiation, they agreed to provide documentation. And what that ended up being was a report by IT company 2 about their understanding of what IT company 1 had done with the firm's systems. Because, I gather, IT company 1 had evaporated. And yes, the core of it was COBOL.
- carlmr 7y ago>I got to learn that we were talking to a service running IBM DataPower Gateway which sat on top of WebSphere which sat on top of the COBOL. As soon as you read IBM you know you have bigger problems than COBOL in your system.
- lunias 7y agoI've been asked by architects to order JSON properties. It's fine until you depend on it. i.e. accessing a map as you would an array https://fasterxml.github.io/jackson-annotations/javadoc/2.3.0/com/fasterxml/jackson/annotation/JsonPropertyOrder.html https://fasterxml.github.io/jackson-annotations/javadoc/2.3....
- peteforde 7y agoI built the first popular sports "app" for the original iPhone, back when Jobs claimed that there was no need to write native code. The backend polled an API that served XML updates on game scores etc. Note that I didn't previously know anything about baseball (and I still don't, not really). So let's say that a baseball team scores a Double. We'd see some XML like <doubles><double/><double/></doubles>. Now, suppose a team scores a tripple... You know that there's a <triples></triples> entity. What would you expect to see inside the node? If you're me, you'd expect to parse <triples><triple/><triple/></triples>. I got the call during dinner. There was an important game happening, and the app suddenly broke. People were uptight. They loved our app and they were complaining. In the end, it turns out that we would need to process <triples><double/><double/></triples>. Why? "Oh, it's always been that way." (Says the brusque developer at the service charging $50k/month for access to this feed.)