10 examples of 'json parse localstorage' in JavaScript

Every line of 'json parse localstorage' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
1function parse(json) {
2 try {
3 return JSON.parse(json);
4 } catch (err) {
5 return null;
6 }
7}
26export function parseJson(json) {
27 return JSON.parse(json, function (k, v) {
28 if (v.indexOf && v.indexOf('function') > -1) {
29 try {
30 return eval('(function(){return ' + v + ' })()')
31 } catch (e) {
32 console.error(`[form-create]解析失败:${v}`);
33 return undefined;
34 }
35 }
36 return v;
37 });
38}
111export function parseJson(json) {
112 return /** @type {?JsonObject} */ (JSON.parse(/** @type {string} */ (json)));
113}
45function parseJSON(json, defaultValue) {
46 return (json ? JSON.parse(json) : defaultValue)
47}
78function parse(load){
79 if ((load.metadata.format === 'json' || !load.metadata.format) &&
80 (isJSON(load.source) || jsonExt.test(load.name))) {
81 try {
82 return JSON.parse(load.source);
83 } catch(e) {
84 var warn = console.warn.bind(console);
85 if(e instanceof SyntaxError) {
86 var loc = this._parseSyntaxErrorLocation(e, load);
87
88 if(loc) {
89 var msg = "Unable to parse " + load.address;
90 var newError = new SyntaxError(msg);
91 newError.promise = this._addSourceInfoToError(newError,
92 loc, load, "JSON.parse");
93 throw newError;
94 }
95 }
96 warn("Error parsing " + load.address + ":", e);
97 return {};
98 }
99 }
100
101 }
4function parseJSON(string) {
5 if (typeof string === "string" &&
6 string.length) {
7 try {
8 return JSON.parse(string)
9 } catch {}
10 }
11
12 return null
13}
79function parseJSON(str) {
80 try {
81 return JSON.parse(`{${str}}`);
82 } catch (err) {
83 return; // eslint-disable-line
84 }
85}
67fromJSON (key: string): any {
68 try {
69 const data: Object = JSON.parse(this.driver.getItem(key))
70 if (data !== null) {
71 if (('ttl' in data) &&
72 Number(data.ttl) < Date.now()) {
73 this.remove(this.removePrefix(key))
74 return null
75 }
76 if ('value' in data) {
77 return data.value
78 }
79 return data
80 }
81 return null
82 } catch (e) {
83 return null
84 }
85}
33function getParsedJson (str) {
34 if (NOT_JSON_CACHE.indexOf(str) > -1) {
35 return str
36 }
37 try {
38 return JSON.parse(str)
39 } catch (error) {
40 NOT_JSON_CACHE.push(str)
41 return str
42 }
43}
4tryParseJSON(json) {
5 let parsed = json;
6 try {
7 parsed = JSON.parse(json);
8 } catch (e) {
9 }
10 return parsed
11}

Related snippets