liveBook · Manning

JSON array

As explained in Just Use Postgres!

A JSON array is an ordered JSON collection of values enclosed in square brackets and accessed by zero-based positions.

A JSON array is an ordered collection of values enclosed in square brackets. In PostgreSQL, chained JSON operators navigate to an array, while a numeric position selects one element; positions start at 0. section 5.4.1

Inspecting a topping

SELECT pizza->'toppings'->'veggies'->0->>'onion' AS onions_amount FROM pizzeria.order_items WHERE order_id = 100; This returns light for the pizza containing the onion ingredient and empty values for other pizzas.

How Just Use Postgres! covers it

How deep it goes
Demonstrates chained extraction, zero-based indexing, scalar retrieval, and containment checks without discussing array internals.
Examples
Uses pizza toppings, vegetable ingredients, tomatoes, onions, and PostgreSQL query output.
What it assumes
Assumes SQL querying and JSON object navigation, while demonstrating array access through concrete PostgreSQL queries.
What you can do after
Apply PostgreSQL's ->, ->>, and @> operators to inspect, index, extract, and filter JSON array contents.
How it connects
Connects JSON arrays with JSON objects, JSON operators, array indexing, and JSON containment.

Also explained in

Compare how 3 books explain JSON array →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.