2014-03-01 23:43:03 +04:00
- - -
l a n g u a g e : j s o n
f i l e n a m e : l e a r n j s o n . j s o n
c o n t r i b u t o r s :
- [ "Anna Harren" , "https://github.com/iirelu" ]
2014-06-09 01:00:14 +04:00
- [ "Marco Scannadinari" , "https://github.com/marcoms" ]
2015-10-08 13:19:51 +03:00
- [ "himanshu" , "https://github.com/himanshu81494" ]
2015-10-15 23:30:59 +03:00
- [ "Michael Neth" , "https://github.com/infernocloud" ]
2018-11-12 22:14:08 +03:00
- [ "Athanasios Emmanouilidis" , "https://github.com/athanasiosem" ]
2014-03-01 23:43:03 +04:00
- - -
2020-10-20 10:47:53 +03:00
J S O N i s a n e x t r e m e l y s i m p l e d a t a - i n t e r c h a n g e f o r m a t . A s [ j s o n . o r g ] ( h t t p s : //json.org) says, it is easy for humans to read and write and for machines to parse and generate.
2014-03-01 23:43:03 +04:00
2023-07-09 09:02:47 +03:00
A p i e c e o f J S O N c a n b e a n y v a l u e o f t h e t y p e s l i s t e d l a t e r , b u t i n p r a c t i c e a l m o s t a l w a y s r e p r e s e n t s e i t h e r :
2017-08-16 22:32:09 +03:00
2015-10-20 11:54:32 +03:00
* A c o l l e c t i o n o f n a m e / v a l u e p a i r s ( ` { } ` ) . I n v a r i o u s l a n g u a g e s , t h i s i s r e a l i z e d a s a n o b j e c t , r e c o r d , s t r u c t , d i c t i o n a r y , h a s h t a b l e , k e y e d l i s t , o r a s s o c i a t i v e a r r a y .
* A n o r d e r e d l i s t o f v a l u e s ( ` [ ] ` ) . I n v a r i o u s l a n g u a g e s , t h i s i s r e a l i z e d a s a n a r r a y , v e c t o r , l i s t , o r s e q u e n c e .
2015-10-08 13:19:51 +03:00
2015-10-20 11:54:32 +03:00
J S O N i n i t s p u r e s t f o r m h a s n o a c t u a l c o m m e n t s , b u t m o s t p a r s e r s w i l l a c c e p t C - s t y l e ( ` //`, `/* */`) comments. Some parsers also tolerate a trailing comma (i.e. a comma after the last element of an array or the after the last property of an object), but they should be avoided for better compatibility.
2015-10-15 23:35:13 +03:00
2015-10-20 11:54:32 +03:00
F o r t h e p u r p o s e s o f t h i s t u t o r i a l , e v e r y t h i n g i s g o i n g t o b e 100 % v a l i d J S O N . L u c k i l y , i t k i n d o f s p e a k s f o r i t s e l f .
2015-10-15 23:35:13 +03:00
2015-10-20 11:54:32 +03:00
S u p p o r t e d d a t a t y p e s :
2015-10-15 23:30:21 +03:00
2015-10-20 11:54:32 +03:00
* S t r i n g s : ` "hello" ` , ` "\"A quote.\"" ` , ` "\u0abe" ` , ` "Newline.\n" `
* N u m b e r s : ` 23 ` , ` 0.11 ` , ` 12e10 ` , ` 3.141e-10 ` , ` 1.23e+4 `
* O b j e c t s : ` { "key" : "value" } `
* A r r a y s : ` [ "Values" ] `
* M i s c e l l a n e o u s : ` true ` , ` false ` , ` null `
2015-10-15 23:35:13 +03:00
2014-03-01 23:43:03 +04:00
` ` ` j s o n
{
2014-06-09 01:00:14 +04:00
"key" : "value" ,
2015-10-08 06:11:24 +03:00
2014-09-21 20:27:43 +04:00
"keys" : "must always be enclosed in double quotes" ,
2014-03-01 23:43:03 +04:00
"numbers" : 0 ,
2014-03-01 23:46:36 +04:00
"strings" : "Hellø, wørld. All unicode is allowed, along with \"escaping\"." ,
2014-03-01 23:43:03 +04:00
"has bools?" : true ,
"nothingness" : null ,
"big number" : 1.2e+100 ,
"objects" : {
"comment" : "Most of your structure will come from objects." ,
2014-03-01 23:46:36 +04:00
"array" : [ 0 , 1 , 2 , 3 , "Arrays can have anything in them." , 5 ] ,
2014-03-01 23:43:03 +04:00
"another object" : {
"comment" : "These things can be nested, very useful."
}
} ,
"silliness" : [
{
"sources of potassium" : [ "bananas" ]
} ,
[
[ 1 , 0 , 0 , 0 ] ,
[ 0 , 1 , 0 , 0 ] ,
[ 0 , 0 , 1 , "neo" ] ,
[ 0 , 0 , 0 , 1 ]
]
] ,
2015-10-08 06:11:24 +03:00
2014-06-09 01:00:14 +04:00
"alternative style" : {
"comment" : "check this out!"
2015-10-20 11:54:32 +03:00
, "comma position" : "doesn't matter, if it's before the next key, it's valid"
2014-06-13 22:20:21 +04:00
, "another comment" : "how nice"
2015-10-20 11:54:32 +03:00
} ,
2015-10-15 23:30:21 +03:00
2015-10-20 11:54:32 +03:00
"whitespace" : "Does not matter." ,
2015-10-15 23:30:21 +03:00
2015-10-20 11:54:32 +03:00
"that was short" : "And done. You now know everything JSON has to offer."
}
2015-10-15 23:30:21 +03:00
` ` `
2015-10-20 11:54:32 +03:00
# # F u r t h e r R e a d i n g
2020-10-20 10:47:53 +03:00
* [ J S O N . o r g ] ( h t t p s : //json.org) All of JSON beautifully explained using flowchart-like graphics.
2018-10-20 18:49:46 +03:00
* [ J S O N T u t o r i a l ] ( h t t p s : //www.youtube.com/watch?v=wI1CWzNtE-M) A concise introduction to JSON.