jsonParseWithUndefined
The jsonParseWithUndefined function parses JSON that was serialized with the jsonStringWithUndefined function, restoring the undefined values within it.
jsonParseWithUndefined(json: string): any| Type | Description | |
|---|---|---|
json | string | The JSON to parse. |
| returns | any | The parsed object, with its |
Use it to read the MergeableContent or MergeableChanges of a MergeableStore that were serialized with that function, so that the Cells and Values they delete stay deleted.
Any string that holds just the Unicode object replacement character (U+FFFC) is read as undefined, including one that was a string Cell or Value when it was serialized.
Examples
This example parses JSON that has an undefined value.
import {jsonParseWithUndefined} from 'tinybase';
const pet = jsonParseWithUndefined('{"species":"dog","color":"\uFFFC"}');
console.log(pet);
// -> {species: 'dog', color: undefined}
console.log(Object.keys(pet));
// -> ['species', 'color']
This example deletes a Cell in one MergeableStore, serializes its content, and then applies it to another MergeableStore that still has that Cell. The Cell is deleted there too.
import {
createMergeableStore,
jsonParseWithUndefined,
jsonStringWithUndefined,
} from 'tinybase';
const store = createMergeableStore();
store.setRow('pets', 'fido', {species: 'dog', color: 'brown'});
const otherStore = createMergeableStore();
otherStore.merge(store);
store.delCell('pets', 'fido', 'color');
const json = jsonStringWithUndefined(store.getMergeableContent());
otherStore.applyMergeableChanges(jsonParseWithUndefined(json));
console.log(otherStore.getTables());
// -> {pets: {fido: {species: 'dog'}}}
Since
v10.2.0