I use undefined and null. I consider myself a rebel. A revolutionary of sorts. No, but basically they just have different use cases. Null is for when you want something to be defined but without value and undefined when undefined, basically saying "this doesn't exist anymore". They are very different.
This is more about how Javascript handles JSON than JSON itself. Most of these were about how the JSON library handles undefined/null/edge cases that don't exist in other languages, and depend on the library you use. All this to say, I did terribly.
NaN and Infinity do exist in other languages. They are part of the Hardware IEEE implementation of floating point numbers. They just don't exist in javascript and every implementation is forced to do something different with it, because there is no solution according to the js specification.
@@krux02They do exist in JavaScript, it's just that the JSON spec has nothing to say about them. So it ends up being a convention of the library. Some will reject them, others will turn them into a string like "-Infinity", others use null... I don't like it. Similar issues with numbers, JSON essentially allows arbitrary precision numbers, but most libraries won't handle it, including JS, which just turns it into a 64-bit float. I updated our library to support full 64-bit signed and unsigned integers, but can't do the same for floating points, because exactly (bitwise) reproducing 64-bit floats is impossible in JSON numbers (different NaNs).
The single fact that JSON has his own native class on JavaScript with just two methods should have already told you that something was fishy over there
Fun fact the JSON global object with parse and stringify was once a library by the Chuck Norris of Javascript, Doug. Browsers just made it native. At the time, it was a security concern that some devs were just doing eval()!
I was a NodeJS developer advocate for Couchbase, a JSON database company. I did well. I got 4 Wrong, but I feel this wasn't really a good test of how will you know JSON, but still interesting
2:52 RUclips hand-picked the exact video that I watched two minutes ago and that led me to watch this video. Are they dumb or do they want me to enter an infinite loop?
Given that I’ve worked on static compiled languages and JavaScript, I would lean towards JavaScript been the problem as JavaScript wants to communicate objects as trees that can be shared across other web layers. Static compiled languages with serialization and deserialization implementations enforce the idea of a developers making their own abstraction to deal with how they want objects to communicate across boundaries as opposed to JS wanting it to put it as a “standard library” for lack of a better term.
Both EMC404 and RFC8259 explicitly do not permit NaN or Infinity for example. I would expect an implementation according to those specifications to throw an error. It's not only JavaScript though. For example in the python standard library you have things like json.loads("Infinity") == math.inf
This is like that WAT presentation by destroy All software on JavaScript type conversion conundrums. 10 years later and we're still roasting JavaScript.
Love this and yesterday's as well. It's software content for software folks, challenging and instructing us as professionals rather than most "coding content" which assumes we know nothing.
Maybe my take on this is a weird one, I feel like many of these questions were not even json related except for maybe the last 3. Sure you parse them through json stringify and parser but the actual values that you used are not really json but more like random strings... As the notation itself states "Javascript Object Notation" just because you give the json parser 353454364566 to parse it doesn't mean its json.
Judging by the amount of time I waste trying to hunt down a missing comma or even a comma too much I knew before watching that I don’t know shit about json
Good format. It was a rollercoaster of emotions, I felt like a genius then like a complete idiot 3 seconds after. PS: Are you planning on making a video on LazyVim? Love u ❤️ u are the very best
1:25 this is not because of json, this is due to how json parsing works in javascript. javascript uses floating point numbers, and when you get to really big numbers you get a precision error because you can't represent them. the json specs say that implementations may do this since, well, they kinda have to, but in theory this is an implementation issue and not a json quirk. also, stringifying any value that is not in the json spec doesn't really test json knowledge, it tests js knowledge.
to quote "programmers are also human" video about javascript: "did you know javascript was actually written in 7 days ... such a messy language ... i love it". Reference: ruclips.net/video/Uo3cL4nrGOk/видео.html
Look, that stringify method isn't a part of the JSON specs. The specs only define the grammar, i.e. what the parsing should obey, and nothing more. So, there's no specs for how to stringify NaN and Infinity or, in fact, anything, really. That said, it makes sense to map NaN and Infinity to "null" (even though it's wrongly printed as 'null', because a JSON string cannot be enclosed with a pair of single quotes).
This game started with "i don't know json" and ended with "okay, i dont even know js"
this hits so much jajajaja
JS is like the meaning of life. We'll never fully know
I’d argue JSON and whatever that mess of a JSON implementation in JS are are two different things.
Exactly. Using JSON with Java or Go is s different story
That's what I was thinking as well
hjson my beloved
@@dejangegic using JSON with Go is even worse because of the zero-values??? Imagine writing a struct with pointers just to check if the value was set.
I’m using JSON in C with some tiny ass library for embedded. It’s sweet, if you parse a broken json it just seg faults
“What possibly can be so difficult about JSON?”
After the video I cried in the corner.
At least you know how to inject dependencies in Spring Boot. I actually didn't know about the @Lookup one, so thank you for that hidden gem!
@@CottidaeSEA Thank you, happy to hear it :)
🤣🤣🤣
Honestly, JSON is pretty reasonable. Javascript, on the other hand, has the worst edge cases. It's like, a stack of knives; nothing but edges.
I feel like half of this video is inspired by me pointing out why I use null in JS.
that is... maybe a good argument
@@ThePrimeagen im curious to know who is json and why is he so important
James "Json" Jansoon
@@andre_julius that explains alot
I use undefined and null. I consider myself a rebel. A revolutionary of sorts.
No, but basically they just have different use cases. Null is for when you want something to be defined but without value and undefined when undefined, basically saying "this doesn't exist anymore". They are very different.
This is more about how Javascript handles JSON than JSON itself. Most of these were about how the JSON library handles undefined/null/edge cases that don't exist in other languages, and depend on the library you use. All this to say, I did terribly.
NaN and Infinity do exist in other languages. They are part of the Hardware IEEE implementation of floating point numbers. They just don't exist in javascript and every implementation is forced to do something different with it, because there is no solution according to the js specification.
@@krux02They do exist in JavaScript, it's just that the JSON spec has nothing to say about them. So it ends up being a convention of the library. Some will reject them, others will turn them into a string like "-Infinity", others use null... I don't like it.
Similar issues with numbers, JSON essentially allows arbitrary precision numbers, but most libraries won't handle it, including JS, which just turns it into a 64-bit float. I updated our library to support full 64-bit signed and unsigned integers, but can't do the same for floating points, because exactly (bitwise) reproducing 64-bit floats is impossible in JSON numbers (different NaNs).
The single fact that JSON has his own native class on JavaScript with just two methods should have already told you that something was fishy over there
Well, it’s not a class, it’s a global object
@@Bozon671_Higgs A Class is an object therefore nobody cares
It is better to parse JSON than just calling eval.. Eval is Evil..
"JavaScript, 💩, an embarrassing toy language used exclusively to build things it's not supposed to."
Fireship quote
a man of culture i see
Tell me... how many did you ackshually get wrong?
DONT LIE
0 because I don't program😎
2
5
JSON spec allows for duplicate keys.
so what will JSON.parse('{"x":1 ,"x":2}') return ?
TOO MANY OKAY?? :'- (
I absolutely loved this video and hated it so much at the same time thanks for this awesome content
i laughed out loud when you said "don't worry it's not going to get any easier"!
That’s more about the absurdity of JavaScript and it’s JSON module and less about JSON.
The dude has great comedic delivery.
The video had me rolling from the getgo.
I feel as though JSON doesn’t even know JSON with that parsed stringify coming back with an error. 😅
who knows whats even happening in there
Fun fact the JSON global object with parse and stringify was once a library by the Chuck Norris of Javascript, Doug. Browsers just made it native. At the time, it was a security concern that some devs were just doing eval()!
I actually knew like half of them. I went into this thinking I might know a couple.
thats pretty good
I was a NodeJS developer advocate for Couchbase, a JSON database company. I did well. I got 4 Wrong, but I feel this wasn't really a good test of how will you know JSON, but still interesting
Then what can be potentially a good test for json ?
Did you know of the {foo: undefined} one? I haven't stumbled upon it but it looks painful. If x is undefined and {foo:x}
@@theodorealenas3171 It's just {}. Doesn't matter if it's a variable or not, it's value-based so if it's undefined, it's undefined.
Wait a minute BIG SAUCE, that property is private, you little mischief
best part is, that private in ts doesnt :)
That's actually a fair point, why doesn't it auto-convert it to private modifier, we must consult the overflows
2:52 RUclips hand-picked the exact video that I watched two minutes ago and that led me to watch this video. Are they dumb or do they want me to enter an infinite loop?
JSON: "never let them know your next move"
Are those behaviors in the spec? Meaning other json parsers should implement them? Sounds more like a JavaScript WAT instead of JSON.
This is something I want to know as well
I think it's both.
Given that I’ve worked on static compiled languages and JavaScript, I would lean towards JavaScript been the problem as JavaScript wants to communicate objects as trees that can be shared across other web layers.
Static compiled languages with serialization and deserialization implementations enforce the idea of a developers making their own abstraction to deal with how they want objects to communicate across boundaries as opposed to JS wanting it to put it as a “standard library” for lack of a better term.
Both EMC404 and RFC8259 explicitly do not permit NaN or Infinity for example.
I would expect an implementation according to those specifications to throw an error.
It's not only JavaScript though. For example in the python standard library you have things like json.loads("Infinity") == math.inf
My morale is now undefined.
I came in rocking like: JSON? It's easy, I'm 100% getting all of them right after I got the first one right, and then I left depressed...
haha
"Ha ha, nerd..."
*Continues furiously taking notes*
Interview questions be like...
This is like that WAT presentation by destroy All software on JavaScript type conversion conundrums. 10 years later and we're still roasting JavaScript.
Only two wrong, a couple guesses though. That's honestly a fun format, you should do it with other APIs as well. (Or one about JS wat-ness)
This is why JS has more bugs than C
Truth
Some of these really feel like they're not the issue of the json specification but of the JS serialiser 😅
it just might be
@@ThePrimeagen doesn't make this any less confusing / fun to guess 😂 Maybe another video with some JS type coercion fun?
I’m extremely new to programming and I know nothing about JavaScript or JSON and I’m angry about this
yes, it should
I hate this game that we're playing
makes me feel things i shouldn't feel
I guess this comes from the fact that JS is completely detached from reality
This video proved me that I did not know that JSON even exist.
Title:- you don't know JSON
The video:- you know nothing, John snow ❄️
I got 10 of them very confidently and I feel absolutely filthy for that.
you filthy filthy internet person
"Somehow, I'm not upset" - Yeah, same here Prime.
It gets even more fun when you try to stringify a sparse array.
Json Statham approves.
The transporter
@@ThePrimeagen I was thinking more along the lines of 'snatch', not that it is related but because it's a good movie.
Oddly satisfying how this guy is shooting against everything and everyone (except for Rust). Keep on going! :D
yayaya! i can shit on rust too!
@ThePrimeagen go and use assembler then!!
Love this and yesterday's as well. It's software content for software folks, challenging and instructing us as professionals rather than most "coding content" which assumes we know nothing.
Man, it's like the "Wat" talk all over again. This language is full of surprises
love this format, thx!
Subtitles:- you don't know JSON
The video:- you know nothing, John snow ❄️
The swamp seeps into the shed built on top of it
no i think this is just great - you're never bored, because every time you get something new!
More arguments about JS being horrible than it being about json
thats always his point
@@dgcp354 ah okay haha didnt know that
I knew this video was going to be cursed once he started to pronounce "JSON" as "jayson" instead of "jawwwwsaawww"
but have you tried Sawcon?
pov: programming gremlin laughs at you as you get a perfect 0% on your job screening
It started with “Hey I know JSON” and the sometime while on the midst of this video, don’t came between i and know 😢
one of the best pieces of content on the internet
"does my ai bot even json?" thats d question
Maybe my take on this is a weird one,
I feel like many of these questions were not even json related except for maybe the last 3.
Sure you parse them through json stringify and parser but the actual values that you used are not really json but more like random strings...
As the notation itself states "Javascript Object Notation" just because you give the json parser 353454364566 to parse it doesn't mean its json.
Personally, I'd rather that it failed on anything other than an object/array literal...
That's indeed a weird take. Numbers and strings are JSON, there's nothing on the standard saying the root element has to be non primitive
@@inakiarias7465 Oh snap, really? Well now it makes complete sense. Thanks for the clarification!
Judging by the amount of time I waste trying to hunt down a missing comma or even a comma too much I knew before watching that I don’t know shit about json
rocket::serde::json::Json. All the JSON I really need to know.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA whyyy JSON, WHYYYYYYYYYYYYYYy
PORQUE JSON!??
This is awesome! Now i know what to ask candidates in an interview for a junior FE position at our company!
now lets pick JSON and put into our MYSQL Database so we have everywhere json :D
i love this idea
and that is how mongo was born
@@ThePrimeagen well i have to use mysql with JSON fields where i have to convert JSON from mysql via PHP to JavaScript :D
Good format. It was a rollercoaster of emotions, I felt like a genius then like a complete idiot 3 seconds after.
PS: Are you planning on making a video on LazyVim?
Love u ❤️ u are the very best
i am thinking about some fun things :)
@@ThePrimeagen FOLKEEEEEEEEE
Whenever you said "Good job" , my disappointment was immeasurable.
hahahahahha
I wish there was a way to json.dumps(indent=4) which would keep composite values with no composite elements in them on one line.
Thank you, Mr. ThePrimeagen!
Jason is a rude anyway. I don't wanna know about him. *sobs*
yeah jason, you need to make up for your actions
Most underrated programming channel
im having an existential crisis
but did you know :
you can create an object and give it the toJSON method and it will take whatever returns from the method as its representation
Software development in 2024: watch other devs coding while copilot is responding
1:25 this is not because of json, this is due to how json parsing works in javascript.
javascript uses floating point numbers, and when you get to really big numbers you get a precision error because you can't represent them.
the json specs say that implementations may do this since, well, they kinda have to, but in theory this is an implementation issue and not a json quirk.
also, stringifying any value that is not in the json spec doesn't really test json knowledge, it tests js knowledge.
I entered this challenge way too confidently.
TOM the genius knows JSON like no other #JDSL
damn i've been completely topped by a random dude with a moustache when it comes to json... what a humiliation...
I just know one day, maybe years from now, one of these nice lil quirks is going to ruin my day.
i don’t get it. why is the A missing from this programming language?
What could be better than javascript? Using javascript logic to transfer your important data!
Might aswell use smoke signals at that point.
this was.... interesting and very entertaining
Hmm that makes me think, can't functions be serialized as WebAssembly bytecode in JSON.
I feel personally attacked because I don't want to admit my own lack of knowledge
This makes sense, and is not weird at all but still thanks for the entertainment
This was so funny. I work with JSON every day but I got absolutely destroyed. 😅
Just had surgery today. Laughing hurts. Laughed at this video. Love hurts.
OMG, It's JSON Bourne!
The new "wat" just dropped.
Thankfully I've never seen this in an interview! I failed 😭
Null is technically an object
to quote "programmers are also human" video about javascript: "did you know javascript was actually written in 7 days ... such a messy language ... i love it". Reference: ruclips.net/video/Uo3cL4nrGOk/видео.html
Good channel! :)
This video made me physically ill.
9/10. Would smash like button again.
You know why Dr Pepper comes in a can'
Man that was demotivating 😂😂
a spiritual sequel to 'wat'
Look, that stringify method isn't a part of the JSON specs. The specs only define the grammar, i.e. what the parsing should obey, and nothing more. So, there's no specs for how to stringify NaN and Infinity or, in fact, anything, really. That said, it makes sense to map NaN and Infinity to "null" (even though it's wrongly printed as 'null', because a JSON string cannot be enclosed with a pair of single quotes).
Json? Barely even know er !
Okay it was entertaining
Javascript is indeed super wacky. I just stick to only using objects and arrays with JSON things
The first one is easy, if you follow the specification a json string is contained between double quotes.
we don't talk about json no no no no
It's always going to be JSML around my house.
you shattered my confidence with JSON lol
I feel attacked by this video
I really like the way you commented on the solutions. Thanks for the entertaining video :)
JSON Statham is the stronkest! 💪😎
😂 that was fun, you should do more videos like this
I implemented json syntax some days ago and I didn't see some of them coming
Simply enlightening for me and my channel! 💪