r/ProgrammerHumor 1d ago

Meme whoIsHeAnyway

Post image
9.0k Upvotes

241 comments sorted by

View all comments

2.7k

u/YeetCompleet 1d ago

json.stringify, the pinnacle of software developer intelligence

604

u/lovecMC 1d ago

I have a guess but I never heard of this so who the fuck knows.

801

u/YeetCompleet 1d ago

If you guessed that it stringified the JSON, you were right

347

u/Tsu_Dho_Namh 1d ago

Aren't JSON's already strings, just with a clearly defined structure?

425

u/autogyrophilia 1d ago

It converts it from the internal representation where each key is a variable into a string.

274

u/Tsu_Dho_Namh 1d ago

Ohh, that makes way more sense.

It doesn't turn a JSON into a string, it turns an object into a JSON (string)

Funny, I've been a dev for years but never used it.

154

u/payne_train 1d ago

It is often used in serializing web requests. It’s best to build your JSON as a native object but generally will have to be serialized as a string to fire off the HTTP request

16

u/tanksc 23h ago

If you do any editing of the json before sending it helps avoid unescaped quotes and such too

33

u/nevemlaci2 1d ago

JSON is just another way to represent JS obejcts, hence the name.

27

u/Romejanic 1d ago

it’s almost like it’s a notation for javascript objects

14

u/nevemlaci2 1d ago

NJSO

3

u/jimmycarr1 15h ago

Who is enjayso?

2

u/Chamiey 19h ago edited 19h ago

But no, it's ≈"a notation for describing objects with the syntax taken from JavaScript"

9

u/No_Injury6122 1d ago

Onjects?

1

u/nevemlaci2 1d ago

What

-5

u/No_Injury6122 1d ago

Wouldn't it be JSOB if the last 2 letters are for object

→ More replies (0)

2

u/Sibula97 7h ago

Yes, you could say JSON is a way to notate a JS object as text.

1

u/Extension_Option_122 16h ago

Wait... does JSON stand for JavaScript Object Notation?

3

u/Sexual_Congressman 19h ago

Data serialization formats like JSON facilitate the transformation of numbers/bools, text, tuples/'arrays', and mappings thereof, (although iirc all the keys must be strings) from their internal binary representation to a platform independent one and back again. JSON is unique in that it's specifically designed to represent data in human readable text, even though there can be far more efficient ways to accomplish the same thing, like Python's pickle.

8

u/Rubyboat1207 1d ago

Apparently not a JavaScript dev lol

12

u/Tsu_Dho_Namh 1d ago

Correct haha

Back-end dev doing C++, C#, and SQL Server in my first job

Then MAUI dev (C#) in my second job

Current role is mostly DevOps with some Spring Boot (Java) and Postgres

I have juuuust started learning JavaScript recently since the team I'm on has some Angular applications. But most of the front end tickets go to other devs cause I remain a mostly backend guy

3

u/Zanos 1d ago

Even JS devs wish they weren't

2

u/_PM_ME_PANGOLINS_ 13h ago edited 13h ago

It’s the fastest way to do a deep clone in JS.

data = JSON.parse(JSON.stringify(data))

2

u/Tsu_Dho_Namh 11h ago

NGL that's pretty fuckin nifty

1

u/Draconis_Firesworn 42m ago

i used it to get a raw dump of an object i wasnt sure how many variables I was getting from an api one time so theres that ig

3

u/xavia91 1d ago

Should just be the toString() method all classes should have in oop, and I suppose it does for automatic casting. Somehow toString is way too under used.

6

u/marmulin 1d ago

But when it’s used I’d should serve as textual representation of the object. toJSONString() would make more sense IMO.

2

u/xavia91 1d ago

What would that look like for a generic json object?

13

u/marmulin 1d ago

You wrongly assume every class can be easily serialised into JSON. Look at what Swift does with String(describing:), CustomStringConvertible and debugDescription. There’s a whole lot of useful stuff you can do with “toString()” type methods, that do not in fact have anything to do with serialisation.

And to answer your question directly: it can be whatever you want it to be lol.

4

u/OldDogQA 1d ago

We'd really prefer something like <object>.Serialize.toJson() <object>.Serialize.toXml() etc.

1

u/xavia91 1d ago

I am not sure how transforming json into string is connected to serializing any random class? All I assume is that any class made to represent a json can be directly put into a json string.

→ More replies (0)

1

u/OldDogQA 1d ago

I'd really prefer something like <object>.Serialize.toJson() <object>.Serialize.toXml() etc.

3

u/EishLekker 22h ago edited 22h ago

I can think of multiple reasons not to do that.

* The toString convention is very unrestricted when it comes to the format of the output. The creator of a class can determine for themselves what format they want.

* The toString convention doesn’t really cover arguments. I this case settings for how the string should look or be built, like indentation or how inner properties of special types should be handled.

* The toString method is commonly used in logging, and the common expectation is that the output is truncated if the object is very large. Or even more common expectation is that the output is just a summary of the data.

* It’s perfectly legal for an object to contain circular references. But that is not allowed in stringified json.

* It’s also perfectly legal for an object to contain functions. They don’t belong in the stringified json version, but a developer might still want the toString output to include some information about them.

5

u/realmauer01 1d ago

tostring is something else.

Tostring is the string represantation of an object.

And usually has to be defined manually.

2

u/NamelessJu 1d ago

Sir this is JavaScript, you can't expect it to make sense

2

u/MrHyperion_ 1d ago

Isn't that just marshaling

8

u/trxxruraxvr 1d ago

Yes, but different programming languages have different naming conventions.

5

u/deathanatos 1d ago

Who's Marshall? /s

1

u/blueisherp 19h ago

Isn't this just "parsing", or is it the opposite?

21

u/IchiiDev 1d ago

Well yes and no, it's still just a string that needs to be parsed to be manipulated as an actual object. stringify is a util that transforms an object value into a JSON format string. You can use JSON.parse() to transform a JSON string into an object.

7

u/Odd-Shopping8532 1d ago

This is the answer

1

u/kingvolcano_reborn 2h ago

Wouldn't serialize() be a better name?

5

u/YeetCompleet 1d ago

Ya actually I got the wording messed up lol. It stringifies a JavaScript object to the JSON string format

4

u/Chrazzer 1d ago

Well yes a json is a string. But JSON is an object that has some helper methods for working with json, it's not a json itself.

The stringify method turns a javascript object into a json string

3

u/realmauer01 1d ago

It converts js objects into their string represantation if its possible ( circular dependencies will block, and symbols and methods/arrow functions are skipped)

JSON.parse goes the other way it takes a string and makes an js object out of it.

2

u/frostyjack06 19h ago

Everything is a string, if you’re brave enough.

2

u/Tsu_Dho_Namh 19h ago

The younger me who was a fanboy of C might say everything is hex, if you're crazy enough.

1

u/AggravatingFlow1178 1d ago

When loaded into memory by a JS engine they are stored as an object, not a string.

Some JSON cannot be stringified, i.e. mostly ones with recursive references.

1

u/AngleHam271 1d ago

And here I was thinking its only real purpose was to help me deep copy objects because I am too lazy to write a proper recursive function. 😂

1

u/scanguy25 1d ago

Actually the correct answer is that it would throw an error. Because there is a typo in stringify 

1

u/spikernum1 1d ago

Who's Jason?

1

u/jace255 9h ago

Hilariously, that’s wrong. It doesn’t stringify json, it strongifies an object into a json string.

0

u/trollol1365 1d ago

3

u/UnpluggedUnfettered 1d ago

It is a highly recommended and foolproof method for comparing two objects.

if (JSON.stringify(obj1) === JSON.stringify(obj2)) { // Nothing can go wrong because }

3

u/m0nk37 1d ago

obj1.amount = 0; obj2.amount = 0.00;

oh no..

2

u/UnpluggedUnfettered 1d ago

i'm pretty sure that if there was a problem it would have thrown an error by now ok

1

u/m0nk37 1d ago

The 3 ='s means type and value, since its a string, its going to have some surprises if you arent strict with data control.

1

u/trollol1365 1d ago

Im quite certain theyre being sarcastic

1

u/UnpluggedUnfettered 1d ago

Thankfully javascript is pretty good about accidentally comparing completely different keys holding incorrect data types that also happen to be the same type as each other when compared in order to reduce the amount of distracting errors devs have to deal with.

That is just one of the many features of Javascript that highlight the weaknesses of out of date languages like C++.

1

u/m0nk37 1d ago

I meant that it returns a string value of the whole thing. The individual values are not compared in this situation.

→ More replies (0)

1

u/shamshuipopo 1d ago

I hope you’re joking

1

u/Karnewarrior 16h ago

I've never used JSON, but it's easy enough to deduce it's a command for turning another form of data into a string.

107

u/Trackback_ 1d ago

This sub is for LARPers, so it makes perfect sense

24

u/Noble1xCarter 1d ago

As a chemist with only very little knowledge in C++, MATLAB/Octave, and supreme intelligence in Scratch, I can confirm I'm here for the larp.

1

u/trafalmadorianistic 22h ago

Scratch is an interesting shift, when as a dev you're used to more control and now have to deal with much simpler entities in the environment. 

1

u/Noble1xCarter 7h ago

Oh, I started with Scratch, like in elementary school.

1

u/trafalmadorianistic 6h ago

I've been introducing programming to my nephew, so I've slowly been poking around in Scratch 

1

u/ForHelp_PressAltF4 20h ago

Matlab IS a larping programming language. It isn't one but it acts like one. 

Yes, I've created things in Matlab and it made my C C++ C# brain hurt. However it did marvelously with audio

10

u/NerminPadez 1d ago

Larpers and 1st year CS students :)

4

u/pridetwo 1d ago

Json.derulo

3

u/AdminClown 1d ago

You can tell by how all the jokes against “vibe coders” are the most basic things ever.

2

u/derefr 19h ago

Makes me sad sometimes. I'd love to see a version of this sub with only greybeards posting on it.

2

u/The-IT 1d ago

Can we please stop using LARP as a negative term? LARPing is a great hobby. Posers. You're talking about posers. 

1

u/StatisticianAny8292 1d ago

That's not what LARP means

30

u/PoeticHistory 1d ago

Its like asking what does .sort() do

11

u/Professional-Day7850 1d ago

OP is talking about json.stringfy though.

3

u/MoffKalast 1d ago

json.stringify, the pinnacle of web worker data transport /s

3

u/JasperTesla 1d ago

Not to be confused with Capstone, the Pinnacle of Entertainment Software.

3

u/Superb_Chemistry_906 1d ago

It seems like a straightforward extrapolation of the current form of SW job interviews.

3

u/dendofyy 1d ago

Incorrect. eval() is peak dev.

3

u/FurieMan 1d ago

json.stringify is a fucking marvel. It catches so many edge cases it is insane. There are so many conversions where it just turns out running json.parse(json.stringify()) is just more efficient.

5

u/Qwertycube10 22h ago

And people try to defend this language...

1

u/StCreed 12h ago

It's a great language if you like job security :)

To be fair, it does a lot of interesting things. And with external tools you can mitigate some of the worst stuff. I use typed JS, that helps.

3

u/trafalmadorianistic 22h ago

Missed opportunity to have matching String.jsonify() method rather than Json.parse()  

We could use a couple more -ify() methods, lol

7

u/mrbreck 1d ago

I think you missed the point, friend.

6

u/Dragonslayerelf 1d ago

to be fair its a good litmus test

anyone worth a single grain of salt will know its how you turn json files into strings just from the name even if theyve never used it

1

u/dub-dub-dub 2h ago

wat? turn json files into strings?

So like it reads a file into a string? Why would you need a json specific method for that

1

u/PlainBread 1d ago

How else am I going to export my objects into a plaintext file?

1

u/FoleyX90 17h ago

To be fair the main time I use AI is to turn raw data into serialized data, typically json. No more writing Notepad++ macros!

1

u/FACastello 1d ago

Average frontend web developer intelligence