Skip to content
Course content preview

17: INSERT and using JSON

Our library is going to need some books. It will also have employees, customers, and the names of the authors of the books. We can use a single table called person here, because a person can be an employee, customer, and book author all at the same time.

As SurrealDB is a document database by default, it works well with large arrays of objects, whether in SurrealQL format or JSON. So if we had the following JSON data for the employees at the library, we could insert it directly into the database without first needing to convert fields like "name" into name.

[
    {
        "name": "Sara Bellum",
        "age": 30        
    },
    {
        "name": "Lydia Wyndham",
        "age": 25        
    },
    {
        "name": "Samm Schwartz",
        "age": 45        
    }
]


The most straightforward way to insert data like this into a table is by using INSERT INTO, followed by the table name.

INSERT INTO person [
{
"name": "Sara Bellum",
"age": 30
},
{
"name": "Lydia Wyndham",
"age": 25
},
{
"name": "Samm Schwartz",
"age": 45
}
];


It has been automatically converted into SurrealQL, which is different but somewhat similar in appearance to JSON.

Output
[
  {
    age: 30,
    id: person:jbcyzmur1jalageanc1u,
    name: 'Sara Bellum'
  },
  {
    age: 25,
    id: person:qjvcx5sd1ee5mi1mpdiq,
    name: 'Lydia Wyndham'
  },
  {
    age: 45,
    id: person:uox9flf3m61wmqm0yybs,
    name: 'Samm Schwartz'
  }
]


Inside SurrealDB Studio (two buttons to the left of the button used to run your queries), you can choose to display output either as SurrealQL or JSON. Unless there is a reason to use JSON, SurrealQL is generally the better option because it is easier to see the type.

Take this query for example.

RETURN [
    time::now(),
    SELECT VALUE id FROM ONLY town LIMIT 1
];


If the display output is SurrealQL, you can always tell that this output holds a datetime and a record ID.

[
  d'2025-02-09T06:05:18.572Z',
  town:wmq63dk1qbgnbhjrnxhj
]


If the display output is JSON, you can eyeball the output and probably conclude that this is a datetime and a record ID, but they might both be strings instead!

[
  "2025-02-09T06:05:40.791Z",
  "town:wmq63dk1qbgnbhjrnxhj"
]


THE PLATFORM

Everything an application and its agents know. Five surfaces, one engine.

IN PRODUCTION

Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.
Justin Foley

VP of Engineering, Later

SurrealDB

The context and memory layer for AI agents

Database. Graphs, vectors, documents and relational data in one engine, in a single ACID transaction.
Agent Memory. Connects and retrieves context wherever your data lives, every fact carrying its source.
Cloud. Fully managed, in the cloud provider and region you choose.

Explore with AI

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom