10 examples of 'jquery string to json' in JavaScript

Every line of 'jquery string to json' 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
this disclaimer
60function json(data) {
61 switch (data) {
62 case '__NULL__':
63 case '__BLANK_ARRAY__':
64 return data === '__NULL__' ? 'null' : '[]';
65 default:
66 return JSON.stringify(data || null, null, ' ')
67 .replace(/\n/g, '')
68 .replace(/^(\{|\[) /, '$1');
69 }
70}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

40function getJsonString(obj) {
41 try {
42 return JSON.stringify(obj);
43 } catch(e) {}
44 return "";
45 }
191function getJsonValue(str) {
192 try {
193 return JSON.parse(str);
194 } catch (e) {
195 return null;
196 }
197}
79function parseJSON(str) {
80 try {
81 return JSON.parse(`{${str}}`);
82 } catch (err) {
83 return; // eslint-disable-line
84 }
85}
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}
9function toJson(string) {
10 try {
11 return JSON.parse(string)
12 } catch (err) {
13 return string
14 }
15}
256function asJSON(str: string): any | null {
257 try {
258 return JSON.parse(str)
259 } catch (e) {
260 return null
261 }
262}
111export function parseJson(json) {
112 return /** @type {?JsonObject} */ (JSON.parse(/** @type {string} */ (json)));
113}
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}
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}

Related snippets