Modified JSON Sheet.
This commit is contained in:
parent
9d24bb8d15
commit
12a3904148
24
JSON.md
24
JSON.md
|
|
@ -32,47 +32,47 @@
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## 1. Introduction to JSON
|
## Introduction to JSON
|
||||||
|
|
||||||
- JSON stands for **JavaScript Object Notation**.
|
- JSON stands for **JavaScript Object Notation**.
|
||||||
- It is a lightweight data interchange format.
|
- It is a lightweight data interchange format.
|
||||||
- JSON is language-independent and easy for humans to read and write.
|
- JSON is language-independent and easy for humans to read and write.
|
||||||
- Commonly used for data exchange between a server and web application, as well as for configuration files.
|
- Commonly used for data exchange between a server and web application, as well as for configuration files.
|
||||||
|
|
||||||
## 2. JSON Data Types
|
## JSON Data Types
|
||||||
|
|
||||||
### 2.1 String
|
### String
|
||||||
|
|
||||||
- Represents a sequence of characters.
|
- Represents a sequence of characters.
|
||||||
- Enclosed in double quotes.
|
- Enclosed in double quotes.
|
||||||
- Example: `"Hello, World!"`
|
- Example: `"Hello, World!"`
|
||||||
|
|
||||||
### 2.2 Number
|
### Number
|
||||||
|
|
||||||
- Represents a numerical value (integer or floating-point).
|
- Represents a numerical value (integer or floating-point).
|
||||||
- Example: `42` or `3.14`
|
- Example: `42` or `3.14`
|
||||||
|
|
||||||
### 2.3 Boolean
|
### Boolean
|
||||||
|
|
||||||
- Represents a logical value, either `true` or `false`.
|
- Represents a logical value, either `true` or `false`.
|
||||||
|
|
||||||
### 2.4 Array
|
### Array
|
||||||
|
|
||||||
- Ordered list of values.
|
- Ordered list of values.
|
||||||
- Enclosed in square brackets `[]`.
|
- Enclosed in square brackets `[]`.
|
||||||
- Example: `[1, 2, "three", true]`
|
- Example: `[1, 2, "three", true]`
|
||||||
|
|
||||||
### 2.5 Object
|
### Object
|
||||||
|
|
||||||
- Unordered collection of key-value pairs.
|
- Unordered collection of key-value pairs.
|
||||||
- Enclosed in curly braces `{}`.
|
- Enclosed in curly braces `{}`.
|
||||||
- Example: `{"name": "John", "age": 30, "city": "New York"}`
|
- Example: `{"name": "John", "age": 30, "city": "New York"}`
|
||||||
|
|
||||||
### 2.6 Null
|
### Null
|
||||||
|
|
||||||
- Represents a null or empty value.
|
- Represents a null or empty value.
|
||||||
|
|
||||||
## 3. JSON Syntax
|
## JSON Syntax
|
||||||
|
|
||||||
- Data is represented in key-value pairs.
|
- Data is represented in key-value pairs.
|
||||||
- Keys are always strings and followed by a colon.
|
- Keys are always strings and followed by a colon.
|
||||||
|
|
@ -80,7 +80,7 @@
|
||||||
- Objects are enclosed in curly braces `{}`.
|
- Objects are enclosed in curly braces `{}`.
|
||||||
- Arrays are enclosed in square brackets `[]`.
|
- Arrays are enclosed in square brackets `[]`.
|
||||||
|
|
||||||
## 4. JSON Example
|
## JSON Example
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -114,7 +114,7 @@ with open('output.json', 'w') as json_file:
|
||||||
json.dump(data_to_write, json_file, indent=4)
|
json.dump(data_to_write, json_file, indent=4)
|
||||||
```
|
```
|
||||||
|
|
||||||
## 6. Accessing JSON Data in JavaScript
|
## Accessing JSON Data in JavaScript
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Assuming jsonString is a JSON string
|
// Assuming jsonString is a JSON string
|
||||||
|
|
@ -125,7 +125,7 @@ console.log(jsonData.name); // Outputs: John Doe
|
||||||
console.log(jsonData.address.city); // Outputs: Anytown
|
console.log(jsonData.address.city); // Outputs: Anytown
|
||||||
```
|
```
|
||||||
|
|
||||||
## 7. Accessing JSON Data in PHP
|
## Accessing JSON Data in PHP
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// Assuming jsonString is a JSON string
|
// Assuming jsonString is a JSON string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue