JSON when you say it out loud sounds like Jason, the first name. “My name is JSON, Theme JSON.”
Theme.json and Block.json are new files in WordPress. Theme.json allows developers to set defaults for color palette, typography, and other design element of a website and control features of the block editor for content creators. Block.json does the same for single blocks, that support certain features like spacing, colors etc. as well as behavior depending on the context. The Developer documentation on WordPress.org has lots of information about those two files.
Introduction to JSON
- What is JSON?
- What is JSON used for?
- Why JSON?
- JSON Syntax
- Data types in JSON
What is JSON?
It is used widely across the internet for almost every single API, as well as for config files and many other places.
It is easy to read and write compared to something like XML because it has a much cleaner syntax.
Code for parsing JSON exists in many languages.
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
- Keys & string values should be wrapped in double quotes
Look at the example below that how a common JSON object looks like:
Data Types and JSON
These Data types can be used in JSON
- Object (JSON Object)
JSON values cannot be one of the following data types:
JSON has eclipsed XML as the preferred data interchange format for web applications and web services.
- Easy mapping into data structures
- Almost all programming languages have libraries or functions that can read and write structures of JSON
- Simple and compact
- It was made to be user-friendly for both people and computers
- It’s flexible
Look at the example below that how a common JSON object looks like vs its XML markup:
Note: XML is a markup language much like HTML, but it was designed to store and transport data.
How to parse received JSON data?
How to send JSON data to an API?
- YouTube Video with Doug Crockford and the JSON Saga
- ECMA-404 The JSON Data Interchange Standard.
(1) “Lightweight” does not mean simple. There are quite long and nested data structures written in JSON. It more refers to the fact that json files are text-based and don’t use a lot of space and are transported fast over the pipelines of the Internet.