Don't like this style? Click here to change it! blue.css
I've never had a dedicated notes about JSON before. It's simple really, so why waste time teaching it.
But it's just really, really, important.
Every coding language has a version of "associative arrays"/"dictionaries".
It's this kinda thing:
let duck = { "name": "Daffy", "sound": "Quack"};
console.log(`Hello ${duck.name}, you make the ${duck.sound} sound.`);
I want to look at how I use Javascript Objects in my day to day life and finally the difference between an "object" and JSON, which is really a data-format.
An object, in code, is basically just a thing that has attributes and methods.
console.log(`Welcome back ${user.first_name}.`);
let response = prompt("By the way, how old are you?");
user.set_age(response);
You can create an object, give it attributes, assign it functions and then call them or access the data or have it call itself.
When I go to make a game from scratch I like to code make an end to end skeleton of the whole concept before getting too mired in details.
That is, I can put in the big ideas and some rough orchestration of how they interact with each other without needing to implement anything.
Almost always this means thinking in groups of data/actions that represent something important to the game. Like an animal or field in a game about farming.
So if I need to roughly structure a lot of ideas that begin to work but don't apply any logic yet, my code will fill-up with "no-ops" and light-weight "objects".
(This rapid-iteration end-to-end impulse is also why I hate TypeScript which I'm sure I'll have heated debates over throughout the semester.)
One of the things you've got to get right in tech is basically just knowing how long things are going to take, roughly.
If you hit "go" on a process and it starts running, and isn't instantly done, you had better know that it will eventually stop running.
(Because the difference between running for an hour and an infinite loop is really important.)
Typically the biggest cost of a long-running algorithm is needing to traverse a lot of data, possibly even traversing a lot of data in the middle of a loop.
Use a dictionary if checking through a big array can possibly be reduced to a single lookup in a dictionary O(1) way better than O(n).
So officially JSON is a "notation" it is a TEXT FORMAT that looks like an object.
'{"name":"Bart","things":[3,4,5], "numeric":5, "subobj":{"key":"value"}}'
A JSON string is an object but with certain structure, comma separated key/value pairs where the keys are in double quotes and the values are either objects, strings, integers or arrays of those things.
It replaced XML as the defacto data transfer style for internet services.
The next topic is REST APIs and most of them speak JSON-in / JSON-out.
let anObject = {'hi':"there"};//this is not JSON it's just a javascript object
let aString = JSON.stringify(anObject);//this is JSON
let deepCopy = JSON.parse(JSON.stringify(anObject));//this is the best javascript way to deep copy an object...