10 examples of 'jquery json to string' in JavaScript

Every line of 'jquery json to string' 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 }
86function jQueryToString($obj) {
87 var i
88 ,stringArray = []
89 ;
90 for (i=0; i<$obj.length; i++) {
91 stringArray.push( elementToString($obj[i]) );
92 }
93
94 return '$('+ stringArray.join(', ') +')';
95}
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}
191function getJsonValue(str) {
192 try {
193 return JSON.parse(str);
194 } catch (e) {
195 return null;
196 }
197}
2function jsonToString(data) {
3 return JSON.stringify(data);
4}
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}
21function jsonify (obj) {
22 var jsonObj,
23 type = objType(obj);
24
25 try {
26 if (type == 'Undefined') {
27 jsonObj = 'undefined';
28 } else if (obj !== obj) {
29 jsonObj = 'NaN';
30 } else {
31 jsonObj = JSON.parse(JSON.stringify(obj));
32 }
33
34 } catch (e) {
35 if (type.match('Element')) {
36 jsonObj = obj.outerHTML.replace(obj.innerHTML, '');
37 } else if (type == 'Text') {
38 jsonObj = textOmit(obj.textContent);
39 } else if (type == 'Array' || type == 'NodeList') {
40 var array = [];
41 obj = slice.call(obj);
42
43 obj.forEach(function (item) {
44 array.push(jsonify(item));
45 });
46 jsonObj = array;
47 } else if (type == 'Object') {
48 var keys = Object.keys(obj),
49 object = {};
50 keys.forEach(function (key) {
51 object[key] = jsonify(obj[key]);
52 });
53 jsonObj = object;
54 } else if (type == 'Function') {
55 jsonObj = textOmit(obj.toString());
56 } else if (type == 'global' || type == 'HTMLDocument') {
57 var keys = Object.keys(obj),
58 object = {};
59 keys.forEach(function (key) {
60 object[key] = objType(obj[key]);
61 });
62 jsonObj = object;
63 } else {
64 jsonObj = toString.call(obj);
65 }
66 }
67
68 return jsonObj;
69}

Related snippets