TinyBase logoTinyBase

setTablesJson

The setTablesJson method takes a string serialization of all of the Tables in the Store and attempts to update them to that.

setTablesJson(tablesJson: string): this
TypeDescription
tablesJsonstring

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

returnsthis

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 TablesSchema associated with the Store).

Examples

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

import {createStore} from 'tinybase';

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

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

import {createStore} from 'tinybase';

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

Since

v3.0.0