Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
You know what's even weirder? A simple string is also a valid json! Like this:
"hello"
mind_blown.tiff -
Actually, valid JSON can also just be a null, boolean, number or string.
Some optional whitespace normally accepted by parsers is missing, but apart from that this link should help you understand, what exactly is valid JSON: https://www.json.org/json-en.html -
Hazarth95192yI mean yeah. Valid json is any valid json value... the outer {} is not a rule, it's a dictionary type sitting at root level. literally any valid json value can be at root level because the root node can be any valid json value. It makes sense when you think about it!
and yeah, if you're writing your own json parser, then either you need to research the specs, or just don't and get a library that does it for you. :) No shame in using other peoples code! Though I think you could technically also use regex at every level that checks for a valid json type at :D -
a valid json can even be simply a "string". or a number. or null. which should be no problem at all, since json parsers exist in the thousands.
unless you're trying to reinvent the wheel by adding your own parser. in which case: _this_ is the source of your despair. -
Root797672yHow is this a surprise?
It isn’t a file format like yaml. It’s just javascript objects. An array is a javascript object. So is 13. -
@Root Actually it is a file/serialization format like YAML. And as YAML is a superset of JSON, of course you can literally put any valid JSON in a YAML file.
-
To clarify, I've been so used to the jsons I've seen and worked with always being {} wrapped I just assumed that the outermost {} was a requirement. No parser writing or anything fancy.
today i learned that not all jsons must be enclosed in curly braces {}
a valid json can have it's outermost things be square brackets as an array []
this is a special kind of pain and despair
rant