Skip to content

Postgres/CockroachDB JSON type not allowing a string to be stored #18

@mcadecio

Description

@mcadecio

Trying to store a string/boolean/integer in column with JSON datatype results in 400.

schema:
CREATE TABLE vehicles.cars
(
manufacturer varchar(50) not null,
car_id bigint primary key not null
constraint cars_car_id_uindex unique,
doors bigint default 5,
last_updated timestamptz default now(),
extra_details json default '{}'
);

Request:

curl -X 'POST'
'http://localhost:8010/cars'
-H 'accept: /'
-H 'Content-Type: application/json'
-d '{
"car_id": 100,
"manufacturer": "Tesla",
"doors": 5,
"last_updated": null,
"extra_details": "type=roadster"
}'

Response:

{
"timestamp": "2024-07-21T09:59:53",
"path": "/cars",
"message": "property 'extra_details' with value "type=roadster" is not a valid OBJECT",
"code": 400,
"errors": []

JSON datatype accepts: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', 'OBJECT', 'ARRAY'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions