W3Schools.com (2024)

The JSON syntax is a subset of the JavaScript syntax.

JSON Syntax Rules

JSON syntax is derived from JavaScript object notation syntax:

  • Data is in name/value pairs
  • Data is separated by commas
  • Curly braces hold objects
  • Square brackets hold arrays

JSON Data - A Name and a Value

JSON data is written as name/value pairs (aka key/value pairs).

A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value:

Example

"name":"John"

JSON names require double quotes.

JSON - Evaluates to JavaScript Objects

The JSON format is almost identical to JavaScript objects.

In JSON, keys must be strings, written with double quotes:

JSON

{"name":"John"}

In JavaScript, keys can be strings, numbers, or identifier names:

JSON Values

In JSON, values must be one of the following data types:

  • a string
  • a number
  • an object
  • an array
  • a boolean
  • null

In JavaScript values can be all of the above, plus any other valid JavaScript expression, including:

  • a function
  • a date
  • undefined

In JSON, string values must be written with double quotes:

JSON

{"name":"John"}

In JavaScript, you can write string values with double or single quotes:

JavaScript

{name:'John'}

JavaScript Objects

Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript.

With JavaScript you can create an object and assign data to it, like this:

Example

person = {name:"John", age:31, city:"New York"};

You can access a JavaScript object like this:

Example

// returns John
person.name;

Try it Yourself »

It can also be accessed like this:

Example

// returns John
person["name"];

Try it Yourself »

Data can be modified like this:

Example

person.name = "Gilbert";

Try it Yourself »

It can also be modified like this:

Example

person["name"] = "Gilbert";

Try it Yourself »

You will learn how to convert JavaScript objects into JSON later in this tutorial.

JavaScript Arrays as JSON

The same way JavaScript objects can be written as JSON, JavaScript arrays can also be written as JSON.

You will learn more about objects and arrays later in this tutorial.

JSON Files

  • The file type for JSON files is ".json"
  • The MIME type for JSON text is "application/json"

W3schools Pathfinder

Track your progress - it's free!

W3Schools.com (2024)
Top Articles
Factory Reset Your Computer's Hard Drive | Electronic Recycling Company
How Many Work Hours in a Year? - ARAHR
Devotion Showtimes Near Xscape Theatres Blankenbaker 16
NOAA: National Oceanic & Atmospheric Administration hiring NOAA Commissioned Officer: Inter-Service Transfer in Spokane Valley, WA | LinkedIn
Gore Videos Uncensored
Klustron 9
How To Get Free Credits On Smartjailmail
Here's how eating according to your blood type could help you keep healthy
Celsius Energy Drink Wo Kaufen
Student Rating Of Teaching Umn
A.e.a.o.n.m.s
The Rise of Breckie Hill: How She Became a Social Media Star | Entertainment
Used Wood Cook Stoves For Sale Craigslist
Charmeck Arrest Inquiry
Fredericksburg Free Lance Star Obituaries
I Touch and Day Spa II
Who called you from +19192464227 (9192464227): 5 reviews
Weather Rotterdam - Detailed bulletin - Free 15-day Marine forecasts - METEO CONSULT MARINE
The Menu Showtimes Near Regal Edwards Ontario Mountain Village
3476405416
Ruben van Bommel: diepgang en doelgerichtheid als wapens, maar (nog) te weinig rendement
Yard Goats Score
Myhr North Memorial
Busted News Bowie County
Drying Cloths At A Hammam Crossword Clue
Craigslist Rome Ny
Black Panther 2 Showtimes Near Epic Theatres Of Palm Coast
Effingham Daily News Police Report
How rich were the McCallisters in 'Home Alone'? Family's income unveiled
Perry Inhofe Mansion
Mrstryst
Mbi Auto Discount Code
Where Do They Sell Menudo Near Me
Vitals, jeden Tag besser | Vitals Nahrungsergänzungsmittel
Giantess Feet Deviantart
Linabelfiore Of
Afspraak inzien
Wsbtv Fish And Game Report
Improving curriculum alignment and achieving learning goals by making the curriculum visible | Semantic Scholar
Aita For Announcing My Pregnancy At My Sil Wedding
814-747-6702
Nimbleaf Evolution
The Cutest Photos of Enrique Iglesias and Anna Kournikova with Their Three Kids
Keci News
Naomi Soraya Zelda
Slug Menace Rs3
Elvis Costello announces King Of America & Other Realms
Lux Funeral New Braunfels
Kidcheck Login
Mike De Beer Twitter
Convert Celsius to Kelvin
How to Choose Where to Study Abroad
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 5592

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.