It’s not a JS object: JSON is always a string. It looks like a JS object because that’s what the design of JSON is based on. But it isn’t, it’s not JS or anything to do with JS: it’s a data interchange format.
It’s useful and very widely used because you don’t send language-specific code between computers (or, often, between programs on a computer). Instead, what gets sent is data, and there needs to be a way to encode the data to a common format at one end (JS has JSON.stringify
to do this, which converts a JS object to a correctly-formatted JSON string), then decode it into something useful the language being used understands at the other end (JS has JSON.parse
for this, which converts correctly formatted JSON to a JS object).
As an example, another data format is .csv, which lets you describe tabular data, eg:
Year,Make,Model
1997,Ford,E350
2000,Mercury,Cougar
Using JSON, that might be written as:
[
{ "year": 1997, "make": "Ford", "model": "E350" },
{ "year": 2000, "make": "Mercury", "model": "Cougar" }
]
Neither of those things have anything to do with a specific programming language, they’re just a way of encoding data in a text form so that it’s easy for both a person and a computer to read or write data from/to it.
In the slightly contrived example used in the challenge, you are getting some data from another computer (fetch
ing it over HTTP). It arrives in the form of JSON. The example uses parse as a demonstration: when you run that, you now have a JS object that you can actually use in the program. It isn’t used, but you could now do things like change the values, as @dav1dborja says. You then want to print that object, visually, to the screen. To do that, it needs to be a string. Because JSON looks exactly like a JS object, running JSON.stringify
will give you that visual representation of the object, so that’s what you can use.