-
Notifications
You must be signed in to change notification settings - Fork 0
JSON
JSON package.json - Holds the metadata relevant to the project. This metadata allows npm to handle the projects dependencies. package-lock.json - This is a public file to ensure consistent install and compatible dependencies. JSON Object syntax & “Key Value” pairs var myObject = { “name”: “Ben”, key → name - value → Ben “age”:29, “city”: null };
JSON Objects can be access the object values with dot (.) AND bracket ( [ ] ) notation. Dot Notation → x = myObject.name; Bracket Notation → x = myObject [“name”]; Creating Nested Values: Used for nested reference types. This describes deeply nested values, such as an array storing objects, which store objects and arrays, which can store more arrays, etc. Reading deeply nested values is a very important technique. If you want to include tweets in one of your future web apps, daily forecasts, or most other data from a third-party source of data, you'll need to know how to read deeply nested data. var superheroes = [ { name: "Spider-Man", alterEgo: { first: "Peter", last: "Parker" }, age: 15, address: { country: "USA", city: "New York" }, favoriteColors: ["blue", "red"] }, { name: "Batman", alterEgo: { first: "Bruce", last: "Wayne" }, age: 32, address: { country: "USA", city: "Gotham" }, favoriteColors: ["black", "yellow"] } ]; people[1].alterEgo.first; // "Bruce" people[0].favoriteColors[1]; // "red" people[1].age; // 32
JSON Methods JSON.stringify() - converts the JSON object into a string format, this allows you to send the JSON object from the browser to another application. (opposite of .parse) Return a JSON string corresponding to the specified value, optionally including only certain properties or replacing property values in a user-defined manner. JSON.parse() - processes a string containing JSON data and converts the data into a JavaScript object ready for the browser to use. (opposite of .stringify) Parse a string as JSON, optionally transform the produced value and its properties, and return the value.