I don't think I disagreed with that. its basically lines of json objects. each line is valid json. you don't interpret the whole file as valid json. It's basically a very simple intermediate filetype.
I feel like JSON5 or JSON6 are our best hopes, because they sound purely like the latest version of JSON and not independent forks, so you have at least a small chance of being able to yell at a vendor "Why doesn't this support JSON6 yet? You're way behind the curve! Next you'll be telling me you don't support Python 4!"
There is a use case for reading comments (though it really needs to be optional) which is if your code is editing the JSON rather than just getting information for it.
Man, what was it? Backspace? Backslash? Some kind of html templating language I had the displeasure to work with in one of my first jobs that used magic comments. I remember my onboarding buddy telling me they didn't do anything, and then discovering that no, they in fact drove the layout of the entire page. He'd been with the company over a year, and wasn't an idiot. It just doesn't make any sense and he hadn't really checked.
Thanks for the link. 22:22 and "Norway problem" are hilarious. I guess I have an excuse now for aggressively quoting everything. Also jsonc looks like much, much better alternative for future projects.
we're talking in context of configuration files that humans read. And most of the problems in that site are avoided by just enclosing the values in quotes and doing logic in whatever uses the yaml. EDIT: Oh i guess the site itself says that too. But yeah it doesn't feel like such a big deal
Heresy. I love it, I'm going to start making unused functions as comments, no I'm going to start embedding AIS you have to chat with to get the comments and they will only tell you the comments if you solve a riddle
They obviously don't know anything about what you really do, but they still have an idea about how you should do it.
I'm sure they press <Enter> at the end of each line in Word, to get a new line - and then curse when everything look like shit after adding/removing one single word.
The #1 place I've seen comments in JSON are where someone makes the mistake of using JSON for a configuration file format. The lack of support for comments is ironically why even XML is a better choice for that. Regardless, you can understand why people would want comments there outside of just dev environments.
(I just learned as of two hours ago that YAML can be used with JSON syntax so I guess it's academic, just use YAML...)
I have done exactly that :( Now I know YAML can be written like JSON though I'm probably going to just switch to that in future as YAML has almost as much support as JSON. I'd only been avoiding it because I thought the indenting-is-meaningful syntax was mandatory.
... I just don't even think about putting \\n at the end of a line and stuff. I never really had a gripe. I guess I've just been someone who is good at following instructions and I don't question this stuff.
No, it was named JSON5 as a subtle nod to HTML5, because it fixed a lot of stuff with the original format when using it for use cases like config files.
HTML 5 came out in 2008, anything older than it is basically not on the internet anymore, and sucks. About the only holdovers from old html stuff (by that I mean stuff that isn't valid anymore but still occasionally happens by beginners ) is <i> for italics and <b> for bold.
Because yaml is just a bolt on extension of JSON. It is json but it lets people omit most of the critical control structures in favor of inferring from whitespace characters.
TOML is indeed better for a lot of things, especially config. Not sure about other places yaml gets used, like in defining CI pipelines. I hate yaml there too however, it always takes me 3 times to get the right incantation for a variable interpolation.
I think something like Jenkins is better there, since its actual code, but Groovy also sucks.
(From what I'm reading it's MOST JSON is valid YAML, but there are differences: JSON allows tabs for indenting, and has some slight differences with escaping - like "\/" is valid JSON but invalid YAML. Surrogate pairs in JSON written like "\uD83D\uDE00" need to be written as "\U0001F600". Bottom line, be aware there are differences, but the main feature of YAML's JSON compatibility is that if the YAML indenting thing isn't very readable to you, you can just write stuff in a more JSON-like way, which, after decades of C and Java and Javascript programming, most of us are used to.)
I mean, it fully ignores white-space outside of strings so you could add whatever random tabs you want in your JSON file. But I wouldn't call it indenting if it has no meaning and is ignored by all valid JSON parsers...
JSON has optional indenting where the tab is just generic white space you can use without it impacting anything. You do not need to indent something in JSON, and it's only meaningful to human readers if you do.
However, tabs ARE meaningful in YAML, under certain circumstances they affect how the file is parsed.
Idk this looks like yaml with extra steps for the most part. You can write bastardized json with bare identifiers etc in yaml and it parses fine. Including iirc curries and squares to replace the white space and “-“ indentation notation if you want.
Edit: Then again if you are writing a config file for humans (ie why you want comments in it), JSON (with or without comments) maybe is not the right choice to start with /IMO
Then I kept running into situations where automation that parsed those comments would've been helpful... It made me hate the fact they exist in the first place.
Either that description or metadata should be serialized into the same object it describes or it shouldn't exist in the same document IMO
Also they allow you to test changes to the config by simply commenting out that line. When editing Configs over ssh this is significantly faster that removing the line and is easier to revert.
json programming, the inventor of rudely telling computers what to do. He has refused to comment on a current political issue and is now getting canceled over this
I think there's room for both JSONC and JSON, though I agree on keeping the base spec simple. Comments really aren't necessary for REST, but they are handy if you're using JSON for configuration. Personally, I think TOML is better for configs, but JSON+comments is probably way easier to implement.
Oh, and even besides complexity, I'm certain that adding in comments would hurt parsing performance which is very important for certain applications.
I think it’s the right choice. JSON is for machine communication, if you could add comments some “genius” would start embedding directives or hints or something in them and basically fork the standard.
Yeah you can also use regex to find and remove trailing commas before parsing. A standardized, agreed upon format would be nicer, but I'm sure there are already a bunch to choose from.
Easy, just add a custom way to handle json into your app, problem solved. Then you get to watch all other JSON parsers yell their lungs out for eternity, and your app is still fine 😊
json is terrible for computer readable. if that's the main goal, pick something that isn't awful. if the goal is readability, json is still not very good, so why use it?
Depends on your parser and where you're defining your json. If you're just creating a JSON file then you should be getting errors because that's not valid JSON. There are other formats like jsonc which just strip the comment lines before parsing to JSON. Apparently the new standard will support comments.
541
u/captain_crocubot 1d ago
I present to you the humble: jsonc
863
u/nameless_pattern 1d ago
You can add anything you want to Json. just make a property called comments
158
u/pregister 1d ago
https://json5.org
76
u/buckinin 1d ago
Comments do exist: { "$comment": "Hello World" }
63
u/mortalitylost 1d ago
I used to like comments in yaml
Then I kept running into situations where automation that parsed those comments would've been helpful... It made me hate the fact they exist in the first place.
Either that description or metadata should be serialized into the same object it describes or it shouldn't exist in the same document IMO
6
u/NightmareJoker2 1d ago
This exists.
6
u/Distinction 1d ago
json5
6
u/notexecutive 1d ago
you can't just add comments in the JDSL alright? They ruin everything and will get you fired! Tom is a genius!
10
u/Random_-account 1d ago
Who is JSON?
5
u/weirdbackpackguy 1d ago
Comments in Jason? I think that's called a tattoo
4
u/AbdullahMRiad 1d ago
jsonc
4
u/DT-Sodium 1d ago
I would have gone with allowing trailing commas.
7
u/Waltekin 1d ago
Yeah, please not. The greatest thing about JSON is its simplicity. The entire spec is only 16 pages long. Don't mess it up.
2
u/nicki419 1d ago
"comment": "This is a comment"
Thank me later
2
u/Successful-Active-21 1d ago
json5 has comments, no ?
2
u/xavia91 1d ago
Wtf is up with all the json bashing and yaml glorification today??
2
u/R15H1_3 1d ago
Just use "_comment" keys like the rest of us suffering in silence.
2
u/No-Shape-2751 1d ago
I think it’s the right choice. JSON is for machine communication, if you could add comments some “genius” would start embedding directives or hints or something in them and basically fork the standard.
2
u/Minimum_Shirt_157 1d ago
You are looking for JSON5
2
u/Dee4WasTaken 20h ago
"comment":"lol"
2
u/kabrandon 15h ago
https://github.com/tailscale/hujson
2
u/za72 1d ago
This may come as a shock but that's what's documentation is for...
I said what I said!
2
u/hearthebell 1d ago
Let's standardize jsonc to the whole internet!
*Whole internet dies
2
u/jensalik 1d ago
You can't do that on my day off....
2
u/abednego-gomes 1d ago
For local configs, you just write comments like
Then you read the file and have a parsing step line by line to strip out any lines starting with // before you do the JSON decode of the whole file.
1
u/Benjamin_6848 1d ago
Why would the genie refuse‽ Comments in JSON could be really useful and a good idea!
1
u/EvenRefrigerator100 1d ago
Better be trailing commas
1
u/Digital_001 1d ago
"Good wish. You still have 3 wishes"
1
u/Optimal-Savings-4505 1d ago
I also stumbled across that limitation, and my solution was to simply add a comment property with a string holding the actual comment.
1
u/LatentShadow 1d ago
Json5 has comments you know...
1
u/dharknesss 1d ago
{"comment":"No."}
1
u/gerbosan 1d ago
Is
devcontainer.jsona JSON file? 😓1
u/KronisLV 1d ago
JSON5: https://json5.org/
Genuinely nice and useful, if you want a format that's less machine-centric than regular JSON.
1
u/Ebuall 1d ago
Jsonc? Most tools already support comments.
1
u/da_Aresinger 1d ago
It is incredibly easy to add comments to any spec.
All you need is the comment sequence and a way to escape it.
It's not a big deal conceptually. But if you're gonna start sending commented Json to other people they'll be very confused.
1
u/jhggiiihbb 1d ago
It’s like no one read the original json spec where they say to run it through a preprocessor for comments.
1
u/CodingChris 1d ago
Or - just don't use json.
1
u/HarryTerraCode 1d ago
But I really want it, no comment in json is sometimes annoying.
1
u/TheZedrem 1d ago
ever heard of jsonc?
1
u/Dimencia 22h ago
Is this a bad language joke that I'm too visual studio to understand?
1
u/NullSmoke 21h ago
Easy, just add a custom way to handle json into your app, problem solved. Then you get to watch all other JSON parsers yell their lungs out for eternity, and your app is still fine 😊
1
u/Respaced 20h ago
Sjson has it.
https://pypi.org/project/SJSON/
Was created by Bitsquid, game engine. (Later Stingray)
1
u/Desperate-Tomatillo7 20h ago
VSCode told met that there is JSONC.
1
u/MACMAN2003 18h ago
The genie is a tyrant!
1
u/RandomiseUsr0 18h ago
“c”:”fill your boots”
1
u/JackNotOLantern 16h ago
Schema, lol
1
u/Direct-Quiet-5817 10h ago
See, 🧞 JSONC 🧞
1
u/joan_bdm 2h ago
hjson you mean?
1
u/kingslayerer 1d ago
Maybe you should start using json schemas. You lazy
0
u/BadgerwithaPickaxe 1d ago
Ai is making you guys less creative, because I have been able to put comments in every single language and framework I've tried.
0
u/ryu____ 1d ago
Add whatever you want in random comment fields. Just don't parse it in any object
-3
u/frayien 1d ago
I've been putting comments in my JSONs since forever and never had any issue with any parser, what is this about ?