1

I am using Sequeal Ace. It says this error

Invalid JSON text: "The document root must not be followed by other values." at position 6 in value for column 'orders.drink'.

CREATE TABLE `orders` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int NOT NULL,
  `drink` json NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

A json that I want to put in.

{"abc": {
    "milk": 100,
    "tea": 100
},
"def":{
    "milk": 100,
    "cola": 100,
}
}
flow Stack
  • 19
  • 1
  • 6

1 Answers1

-2

Using your table I managed to do a simple insert with the following query. You need to just add quotation marks to the main keys in the object.

INSERT INTO orders (id, user_id, drink, meal)  VALUES(2, 2,  '{"yoji": {
    "milk": 100,
    "barley_tea": 100,
    "soy_milk": 100
  },
  "nyuji":{
    "milk": 100,
    "barley_tea": 100,
    "soy_milk": 100}
}', 'asd');

arm
  • 145
  • 1
  • 5