logo
📚 其他

JSON

JSON Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · 其他🧭 Markdown 速查🏷️ 2 个标签
#json#data
向下滚动查看内容
返回全部 Cheat Sheets

Getting Started

Introduction

JSON is a lightweight text-based open standard designed for human-readable data interchange.

  • JSON stands for JavaScript Object Notation
  • JSON is easy to read and write.
  • JSON is language agnostic data-interchange format
  • JSON filename extension is .json
  • JSON Internet Media type is application/json

{.marker-round}

Examples
JSON
滚动查看更多
{
	"name": "Jason",
	"age": 39,
	"height": 1.92,
	"gender": "M",
	"salary": 70000,
	"married": true,
	"children": [
		{ "name": "Tom", "age": 9, "gender": "M" },
		{ "name": "Ava", "age": 7, "gender": "F" }
	]
}
Types
TypeDescription
NumberDouble precision floating-point
StringSeries of characters
Booleantrue or false
ArrayOrdered sequence of values
ValueString, Number, Boolean, null etc
ObjectUnordered collection of key/value pairs
nullNull or Empty
String
\"Double quote
\\Backslash
\/Forward slash
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tTab
\uTrailed by four hex digits

Examples

JSON
滚动查看更多
{
	"url": "https://cheatsheets.zip",
	"msg": "Hi,\n\"CheatSheets.zip\"",
	"intro": "Share quick reference and cheat sheet for developers."
}

Invalid String

JSON
滚动查看更多
{ "foo": "bar" }

Have to be delimited by double quotes

Number
TypeDescription
IntegerDigits 1-9, 0 and positive or negative
FractionFractions like 0.3, 3.9
ExponentExponent like e, e+, e-, E, E+, E

Examples

JSON
滚动查看更多
{
	"positive": 12,
	"negative": -1,
	"fraction": 10.25,
	"exponent": 1.0e2,
	"zero": 0
}

Invalid Number

JSON
滚动查看更多
{ "foo": 0xff }

In JSON you can use only Decimal Literals

Objects
JSON
滚动查看更多
{
	"color": "Purple",
	"id": "210",
	"composition": {
		"R": 70,
		"G": 39,
		"B": 89
	},
	"empty_object": {}
}

Multiple key/value pairs separated by a comma

Arrays
JSON
滚动查看更多
[1, 2, 3, 4, 5]

Begins with [ and ends with ]

Array of objects
JSON
滚动查看更多
{
	"children": [
		{ "name": "Jimmy Smith", "age": 15 },
		{ "name": "Sammy Sosa", "age": 12 }
	]
}
Object of arrays
JSON
滚动查看更多
{
	"attributes": ["a1", "a2"],
	"methods": ["getter", "setter"],
	"empty_array": []
}
2D Array
JSON
滚动查看更多
{
	"my_sequences": [
		[1, 2, 3],
		[4, 5, 6],
		[7, 8, 9, 0],
		[10, 11]
	]
}
Object of objects
JSON
滚动查看更多
{
	"Mark McGwire": {
		"hr": 65,
		"avg": 0.278
	},
	"Sammy Sosa": {
		"hr": 63,
		"avg": 0.288
	}
}
Nested
JSON
滚动查看更多
{
	"Jack": {
		"id": 1,
		"name": "Franc",
		"salary": 25000,
		"hobby": ["a", "b"],
		"location": {
			"country": "A",
			"city": "A-A"
		}
	}
}

Access JSON in JavaScript

Access Object
JAVASCRIPT
滚动查看更多
let myObject = {
	name: 'Jason',
	last: 'Doe',
	age: 39,
	gender: 'M',
	salary: 70000,
	married: true
};

myObject.name"Jason"
myObject["name"]"Jason"
myObject.age39
myObject.otherundefined
myObject[0]undefined
Access Nested
JAVASCRIPT
滚动查看更多
let myObject = {
	ref: {
		name: 0,
		last: 1,
		age: 2,
		gender: 3,
		salary: 4,
		married: 5
	},
	jdoe: ['Jason', 'Doe', 39, 'M', 70000, true],
	jsmith: ['Tom', 'Smith', 42, 'F', 80000, true]
};

myObject.ref.age2
myObject["ref"]["age"]2
myObject.jdoe["Jason", "Doe", 39 ...]
myObject.jsmith[3]"F"
myObject[1]undefined
Access Array of Objects
JAVASCRIPT
滚动查看更多
let myArray = [
	{
		name: 'Jason',
		last: 'Doe',
		age: 39,
		gender: 'M',
		salary: 70000,
		married: true
	},
	{
		name: 'Tom',
		last: 'Smith',
		age: 42,
		gender: 'F',
		salary: 80000,
		married: true
	},
	{
		name: 'Amy',
		last: 'Burnquist',
		age: 29,
		gender: 'F',
		salary: 60000,
		married: false
	}
];

myArray[0]{"name": "Jason", ...}
myArray[1].name"Tom"
myArray[1][2]42
myArray[3]undefined
myArray[3].genderTypeError: Cannot read...
Access Array
JAVASCRIPT
滚动查看更多
let myArray = ['Jason', 'Doe', 39, 'M', 70000, true];

myArray[1]"Doe"
myArray[5]true
myArray[6]undefined

Also see

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572