TinyBase logoTinyBase

setValuesJson

The setValuesJson method takes a string serialization of all of the Values in the Store and attempts to update them to those values.

setValuesJson(valuesJson: string): this
TypeDescription
valuesJsonstring

A string serialization of all of the Values 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 setValues method (according to the Values type, and matching any ValuesSchema associated with the Store).

Examples

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

import {createStore} from 'tinybase';

const store = createStore();
store.setValuesJson('{"open": true}');
console.log(store.getValues());
// -> {open: true}

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

import {createStore} from 'tinybase';

const store = createStore();
store.setValuesJson('{"open": false');
console.log(store.getValues());
// -> {}

Since

v3.0.0