JSON
Write, parse, validate, and exchange interoperable JSON using current standards.
Syntax and Values
Use the complete JSON value model and structural grammar.
Represent primitive and structured values.
{"name":"Ana","active":true,"score":98,"note":null}Format JSON without changing its data.
{"id":1,"name":"Ana"}Objects
Store unordered name and value pairs.
Create objects with quoted, unique property names.
{"name":"Ana","age":30}Arrays
Store ordered sequences of JSON values.
Create ordered lists with mixed valid values.
["red","green","blue"]Strings and Unicode
Encode Unicode text and escaped characters correctly.
Escape quotes, slashes, controls, and Unicode.
{"message":"She said \"hello\"."}Exchange interoperable JSON over networks.
Content-Type: application/jsonNumbers and Literals
Use interoperable numbers, booleans, and null.
Represent integers, fractions, and exponents.
[0,-12,3.14,6.02e23,-2E-3]Represent logical states and missing values.
{"enabled":true,"archived":false,"owner":null}JavaScript
Parse and serialize JSON safely in JavaScript.
Convert JSON text to a JavaScript value.
const data = JSON.parse('{"name":"Ana"}')Convert a JavaScript value to JSON text.
const text = JSON.stringify({ name: 'Ana', active: true })Python
Decode and encode JSON with the standard library.
Convert between JSON text and Python values.
import json
data = json.loads('{"name":"Ana"}')
text = json.dumps(data)Read and write UTF-8 JSON files.
with open('data.json', encoding='utf-8') as file:
data = json.load(file)JSON Schema
Describe and validate JSON documents with Draft 2020-12.
Validate object properties and required fields.
{"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object"}Validate collections and combine reusable rules.
{
"type":"array",
"items":{"type":"string"},
"uniqueItems":true
}Pointer and Patch
Address values and describe partial document changes.
Address a value using RFC 6901 path tokens.
/users/0/nameDescribe ordered changes with RFC 6902 operations.
[ {"op":"replace","path":"/name","value":"Ana"} ]Validation and Security
Reject invalid input and avoid interoperability traps.
Recognize syntax accepted by JavaScript but not JSON.
Invalid:
{'name':'Ana'}
{"active":True}
{"items":[1,2,]}Treat parsed JSON as untrusted structured input.
const data = JSON.parse(untrustedText)
validate(data)