Adding a key(Path) to JSON-Object with sharedb and json0-ot-type

331 views Asked by At

I am currently working with sharedb (https://share.github.io/sharedb/) and the operationel transformation type json0 (https://github.com/ottypes/json0). I need to add a key (path) to a JSON object afterwards, which should be shared via sharedb.

For example, the key "key2" should be added to the following JSON object:

{
   key1: 'some_value',
}

Unfortunately, according to the documentation of json0 (https://github.com/ottypes/json0), there is no operation for this, which surprises me a lot. How can I add a new key that will be recognized by sharedb? Simply adding the key (path) locally makes sharedb not recognize it!

1

There are 1 answers

1
Alec On BEST ANSWER

The docs you shared say:

{p:[path,key], oi:obj} inserts the object obj into the object at [path] with key key.

So you'd want to use that oi ("object insert") op shape:

const op = [{p: ['key2'], oi: 'some_other_value'}]
doc.submitOp(op)