TinyBase

setJson

The setJson method takes a string serialization of all of the Tables in the Store and attempts to update it to that value

setJson(json: string): Store
TypeDescription
jsonstring

A string serialization of all of the Tables in the Store.

returnsStore

A reference to the Store.

If the JSON cannot be parsed, this will fail silently. If it can be parsed, it will then be subject to the same validation rules as the setTables method (according to the Tables type, and matching any Schema associated with the Store).

Examples

This example sets the contents of a Store from a serialization.

const store = createStore();
store.setJson('{"pets":{"fido":{"species":"dog"}}}');
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}}}

This example attempts to set the contents of a Store from an invalid serialization.

const store = createStore();
store.setJson('{"pets":{"fido":{');
console.log(store.getTables());
// -> {}