-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE TABLE mik (
    id INTEGER NOT NULL,
    doc JSON,
    PRIMARY KEY(id)
);
INSERT INTO mik VALUES(1, '{}');
SELECT doc FROM mik WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.a', 123) WHERE id = 1;
SELECT doc FROM mik WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.b', 'ABC') WHERE id = 1;
SELECT doc FROM mik WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c', '{}') WHERE id = 1;
SELECT doc FROM mik WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c',JSON_SET(doc->>'$.c', '$.c1', JSON_OBJECT())) WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c', JSON_SET(doc->>'$.c', '$.c1', JSON_SET(doc->>'$.c.c1', '$.c1x', JSON_OBJECT('x', 1)))) WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c', JSON_SET(doc->>'$.c', '$.c1', JSON_SET(doc->>'$.c.c1', '$.c1y', JSON_OBJECT('y', 2)))) WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c',JSON_SET(doc->>'$.c', '$.c2', JSON_OBJECT())) WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c', JSON_SET(doc->>'$.c', '$.c2', JSON_SET(doc->>'$.c.c2', '$.c2x', JSON_OBJECT('x', 3)))) WHERE id = 1;
UPDATE mik SET doc = JSON_SET(doc, '$.c', JSON_SET(doc->>'$.c', '$.c2', JSON_SET(doc->>'$.c.c2', '$.c2y', JSON_OBJECT('y', 4)))) WHERE id = 1;
SELECT doc FROM mik WHERE id = 1;
SELECT doc->>'$.c.c1.c1x',doc->>'$.c.c2.c2y' FROM mik;
DROP TABLE mik;
