8 ms·
JSON plus comments and python-style multi-line strings is great. The thing where you can leave quotes off strings makes me nervous, especially the example wher
by simonw 11y ago
JSON plus comments and python-style multi-line strings is great.
The thing where you can leave quotes off strings makes me nervous, especially the example where the value is HTML with its own embedded double quotes for attribute values.
Not requiring quotes on strings like that looks like an obvious vector for injection attacks. I guess Hjson isn't designed to be generated automatically, but I'd prefer a format that is easy to generate safely.
What I really want is JSON plus comments plus multi-line strings plus relaxed rules on trailing commas... While maintaining as simple and unambiguous a parsing model as possible.
- jaquers 11y agoHave you looked at JSON5? http://json5.org/ http://json5.org/
- novaleaf 11y agoi've used json5 since the beginning. it's great! just a couple week ago they merged in descriptive error messages too. No more wondering where the bug is!
- paulannesley 11y agoJSON5 looks really good. I'm not sure about this one part though, from a point of view of simplicity and interoperability when deserializing the data: > Numbers can include Infinity, -Infinity, NaN, and -NaN.
- echlebek 11y agoThis is a good thing. It means there is a 1:1 mapping between numbers in JSON5 and IEEE floats.
- zyxley 11y agoStrings without quotes leads to all kinds of trouble in YAML. You end up just quoting everything anyway the first time you need to use "false" or "[some words here]" as a string.
- crdoconnor 11y agoThis ought be fixed by making YAML explicitly rather than implicitly typed. E.g. x: yes >>> str(yaml['x']) yes >>> bool(yaml['x']) True
- mamikonyana 11y agohow about yaml? http://www.yaml.org/start.html http://www.yaml.org/start.html
- bpicolo 11y agoyaml has any number of ambiguous cases
- andrei_says_ 11y agoCould you provide some examples?
- bpicolo 11y agoUnquoted strings are valid in yaml just like this format. There are at least 2 ways to specify a list of things. There are some super bizarre looking possible formats for lists of mapping types. There are a number of others given the length of the spec. Yaml is a complicated beast that generally has more than one way to do any given thing
- TranquilMarmot 11y agoFrom hjson.org: "YAML expresses structure through whitespace. Significant whitespace is a common source of mistakes that we shouldn't have to deal with."
- jholman 11y agoOkay, does anyone actually believe that causes a problem? I can think of ONE time when that causes a problem, and that's with indentation with multi-line strings. Oh look, HJSON included that feature. That's like throwing the baby out and keeping all the bathwater.
- gboone42 11y agoI can't find a specific example off the top of my head but I'll say I've been managing a Jekyll site for a while now and whitespace errors in frontmatter and data files cause all kinds of problems. I'm not sure I could explain the details but it's a legit criticism of YAML. IMO part of the problem is that YAML looks very straightfowrard and is until it suddenly isn't. Whitespace is part of that problem.
- jcoffland 11y agoI came here to make the same comment. The ability to leave off quotes on strings is a misfeature which overly complicates the language. Also I see no need for three different comment styles.
- nix0n 11y agoUse what you want, ignore the rest. Like C++.
- deleted 11y ago[deleted]
- talles 11y agoI prefer to openly discuss the features while giving the authors feedback instead of just ignoring what I don't want, but that's just me.
- creshal 11y agoThat might work for programming languages (C++'s bad rep nonwithstanding), but for data exchange formats you cannot cherrypick features, you have to support the whole spec, and nothing else.
- kbenson 11y agoI think it's more nuanced than that. You must be strict in what you emit, but can be liberal in what you accept. That liberalness can go too far though, and should not make parsing brittle, or encourage misuse of the spec. It's there more to allow someone's unambiguous mistakes to still parse. - Accidentally left in a final comma on a list? That's okay, that only means one thing, we understand. - Allow non-quoted keys on objects? Well, we understand JavaScript generally allows this, so we'll let it slide. This time. - Make newline significant and define new items? Okay, are we just ignoring space efficient payloads now? Should making it space efficient mean changing formats from Hjson to json? - Considering all terms in place of a object value a string until a newline? Are you just trolling me now? How is that more human readable? Does your spoken language not use quotes to distinguish distinct chunks of communication or something, and if so, does it use a Latin alphabet so it's off-putting when you see them? Needless to say, I'm really confused by the reason this even exists.
- david-given 11y agoIf trailing commas and quotation marks are optional, then does this: foo: 4, ...produce the value 4, "4", or "4,"?
- PuerkitoBio 11y agoFrom the docs: > When you omit quotes the string ends at the newline. > Preceding and trailing whitespace is ignored as are escapes. > > A value that is a number, true, false or null in JSON is > parsed as a value. E.g. 3 is a valid number while 3 times is > a string. (edit: formatting)
- lumpypua 11y agoRight but the point is that you had to consult the docs. It's a problem of ambiguity on the part of the format.
- chris-at 11y agoOf course you have to get the information from somewhere the first time you learn something. What's the problem with that?
- dandelany 11y agoThe problem is that this is supposed to be a more-easily-readable form of JSON, but it requires consulting the docs to understand the meaning of something which is completely unambiguous in regular JSON.
- ssalazar 11y ago> Of course you have to get the information from somewhere the first time you learn something. What's the problem with that? The first time, and the second time if you haven't looked at it in a month, and a third time a month after that. And so on.
- PuerkitoBio 11y ago
- rymohr 11y agoTake a look at HONEY: https://github.com/honey/honey https://github.com/honey/honey Primary goals were to remove as much syntax as possible and make it play well with line-based diffs (with the hopes that someone who knows knowing about the language could resolve conflicts without getting tripped up by surrounding quotes, trailing comments, etc).
- lomnakkus 11y agoUnfortunately, conflicts in white-space based languages can get even worse than regular conflicts because you have very few visual structural "anchors" to start to gain an understanding of the conflict. (If you have to resolve manually, that is.) Granted, if the number of conflicts which cannot be automatically resolved is reduced by enough, then it might not matter in the grand scheme of things. However, I'd be worried that this would make "accidental" automatic resolution of semantic conflicts more common. That may be an unfounded/irrational fear, I don't know.
- kbenson 11y ago> The thing where you can leave quotes off strings makes me nervous, especially the example where the value is HTML with its own embedded double quotes for attribute values. Learn from Perl. The quote operator is your friend (and I frequently lament it's omission in Bash). You could simplify it by not using the matching enclusures ({ and }, [ and ], etc). It's easy to parse. and if you keep the quoting character somewhat rare, it's not hard to read. E.g. { "string" : "A string without inner quotes", "quotes1" : q!A string "with" inner quotes!, "quotes2" : q|A string "with" inner quotes|, "quotes3" : q@A string "with" inner quotes@, "quotes4" : qTA string "with" inner quotesT, } Edit: To be clear, I wish JavaScript had a quote operator, and JSON started with it. :/ 1: http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Ope...
- fredley 11y agoI haven't used Perl in quite some time, and this is the sort of thing is why it was bad. Quotes are quotes are quotes in almost every language. It's completely unambiguous, the downside is that you sometimes need to escape them. This, on the other hand, is a 'solution' to escaping quotes that is completely mad. Using non-standard quotes, especially mixing and matching them is a disaster for readability and maintainability (using a T in your string now? need to change the quotes!). Triple quotes are just find if you want to avoid escapes, and hjson seems to support them.
- kbenson 11y ago> Quotes are quotes are quotes in almost every language. It's completely unambiguous Oh, like in C and C++ where single quotes denote a char, and double quotes a string? Or in Perl, PHP and Ruby where double quotes interpolate, and single quotes don't? Or in JavaScript and Python, where there's no functional difference between single and double quotes? Or C#'s string literals which only support double quotes, but you prefix the string with @ to denote it's verbatim? Or systems that allow repeated double quotes within a double quote string literal to stand in for an escape ("foo ""bar"" baz"), as many SQL systems do? Or what about systems that interpolate, and the differences between what they do and do not interpolate? Variables? Escape characters? Hexadecimal escapes? You're fooling yourself if you think it unambiguous in anything except for the language you are dealing with, and if you're within that language, who cares what you use as long as it's consistent? You learn it, and then it's unambiguous (if implemented well). This is no different than if your language supports hex numbers (usually done through prefixing it with 0x). Those are two different ways to specify the exact same thing (a binary number!). The benefit comes from using it in the circumstance where it's appropriate. That is, where it enhances readability, not where it detracts from it. > This, on the other hand, is a 'solution' to escaping quotes that is completely mad. Using non-standard quotes, especially mixing and matching them is a disaster for readability and maintainability Maybe you think "{\"foo\":\"bar\",\"baz\":\"it's that's they're we're\"}" is fine, or you may prefer '{"foo":"bar","baz":"it\'s that\'s they\'re we\'re"}' (if your language supports it). I prefer q|{"foo":"bar","baz":"it's that's they're we're"}| because I think it's clearer, and learning once that a literal q defines a new quote operator that is in effect until it's next seen is simple, easy to remember, and yields very useful readability gains. > using a T in your string now? need to change the quotes! I included the qTT example just to show how it worked, not to endorse its use. I thought that would have been obvious from my statement "You could simplify it by not using the matching enclosures ({ and }, [ and ], etc). It's easy to parse. and if you keep the quoting character somewhat rare, it's not hard to read." In any case, I fail to see how how that's a problem beyond any other quote character. Including that character in your string will result in a compile time error in all but the most esoteric of cases, making it easy to find.
- JoshTriplett 11y agoI like that you can leave the quotes off of keys, which should always parse as identifiers. (And those that don't should require quotes.) Leaving the quotes of values seems like the problem.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- aleem 11y agoDo checkout http://json5.org/ http://json5.org/ based off the original JSON author Doug Crockford's own proposed parser extensions, primarily trailing commas and comments, both of which have been a point of contention pretty much the day since the day JSON landed. It's a much simpler and saner proposal. Trailing commas and JSON comments are are already supported in the newer browsers (try the Chrome console for instance). Fortunately quoteless strings or optional-commas/newline-separator as proposed in Hjson will never fly. They are brittle and ambiguous. Who knows what will this get parsed as: { a: hello's and hi's have 'misplaced' apostrophes b: ball: a round # and # bouncy object c: cakes and candy: both have sugar # but how do I include a hash at the start of a multiline-unquoted string? }
- masklinn 11y ago> Trailing commas and JSON comments are are already supported in the newer browsers (try the Chrome console for instance). Version 49.0.2623.112 (64-bit) > JSON.parse('{"foo": "bar",}') > VM124:1 Uncaught SyntaxError: Unexpected token } Javascript object literals != JSON. JSON is a restricted subset of JS object literals (and not actually a strict subset: a JSON string can contain unescaped U+2028 "LINE SEPARATOR" and U+2029 "PARAGRAPH SEPARATOR" codepoints, a Javascript string can not)