Every line of 'json stringify newline' 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.
28 function JSON_stringify(s, emit_unicode) { 29 if (s) { 30 var json = JSON.stringify(s); 31 if (json) { 32 return emit_unicode ? json : json.replace(jsonRegex, jsonRegexReplace); 33 } 34 else { 35 return json; 36 } 37 } 38 else { 39 return s; 40 } 41 }
1312 static stringify(object, toEncodable, indent) { 1313 let output = new core.StringBuffer(); 1314 _JsonStringStringifier.printOn(object, output, toEncodable, indent); 1315 return dart.toString(output); 1316 }
52 function stringifyValue (value, space, indent, limit) { 53 // boolean, null, number, string, or date 54 if (typeof value === 'boolean' || value instanceof Boolean || 55 value === null || 56 typeof value === 'number' || value instanceof Number || 57 typeof value === 'string' || value instanceof String || 58 value instanceof Date) { 59 return JSON.stringify(value) 60 } 61 62 // array 63 if (Array.isArray(value)) { 64 return stringifyArray(value, space, indent, limit) 65 } 66 67 // object (test lastly!) 68 if (value && typeof value === 'object') { 69 return stringifyObject(value, space, indent, limit) 70 } 71 72 return undefined 73 }
12 export function stringify(object, indent = 2) { 13 return JSON.stringify(cloneWithJsonReferences(object), null, indent); 14 }
293 writeNewline() { 294 return (this.pretty) ? this.newline : ''; 295 }
23 export function jsonStringify(value: any) { 24 return JSON.stringify(value, replacer) 25 }
140 function stringify(obj) { 141 // Implement a stable JSON.stringify 142 // Object's keys are alphabetically ordered 143 var key, 144 key_list, 145 i, 146 value, 147 result_list; 148 if (obj === undefined) { 149 return undefined; 150 } 151 if (obj === null) { 152 return 'null'; 153 } 154 if (obj.constructor === Object) { 155 key_list = Object.keys(obj).sort(); 156 result_list = []; 157 for (i = 0; i < key_list.length; i += 1) { 158 key = key_list[i]; 159 value = stringify(obj[key]); 160 if (value !== undefined) { 161 result_list.push(stringify(key) + ':' + value); 162 } 163 } 164 return '{' + result_list.join(',') + '}'; 165 } 166 if (obj.constructor === Array) { 167 result_list = []; 168 for (i = 0; i < obj.length; i += 1) { 169 result_list.push(stringify(obj[i])); 170 } 171 return '[' + result_list.join(',') + ']'; 172 } 173 return JSON.stringify(obj); 174 }
216 function prettyPrintJson(obj, indent) { 217 var result = ''; 218 219 if (indent == null) indent = ''; 220 221 for (var property in obj) { 222 if (property.charAt(0) !== '_') { 223 var value = obj[property]; 224 225 if (typeof value === 'string') { 226 value = '\'' + value + '\''; 227 } else if (typeof value === 'object') { 228 if (value instanceof Array) { 229 value = '[ ' + value + ' ]'; 230 } else { 231 // Recursive dump 232 var od = prettyPrintJson(value, indent + ' '); 233 234 value = '{\n' + od + '\n' + indent + '}'; 235 } 236 } 237 result += indent + property + ': ' + value + ',\n'; 238 } 239 } 240 return result.replace(/,\n$/, ''); 241 }
3 function formatJson(obj, space, level) { 4 if (!obj) { 5 return; 6 } 7 if (typeof space === 'undefined') { 8 space = ''; 9 } 10 if (typeof level === 'undefined') { 11 level = 0; 12 } 13 14 var indent = ' '; 15 var isArr = Array.isArray(obj); 16 var ret = ''; 17 var val; 18 19 for (var key in obj) { 20 if (isArr) { 21 ret += space + indent; 22 } else { 23 ret += space + indent + key + ': '; 24 } 25 26 val = obj[key]; 27 28 if (val instanceof Date || val instanceof moment) { 29 val = val.toString(); 30 } 31 32 if (Array.isArray(val) || typeof val === 'object') { 33 ret += formatJson(val, space + indent, level + 1); 34 } else { 35 if (typeof val === 'string') { 36 val = '"' + val + '"'; 37 } 38 ret += val + ',\n'; 39 } 40 } 41 42 if (key && endsWith(ret, ',\n')) { 43 ret = ret.substr(0, ret.length - 2) + '\n'; 44 } 45 46 if (isArr) { 47 ret = (level > 0 ? '' : space) + '[\n' + ret + space + ']' + (level > 0 ? ',\n' : ''); 48 } 49 else { 50 ret = (level > 0 ? '' : space) + '{\n' + ret + space + '}' + (level > 0 ? ',\n' : ''); 51 } 52 return ret; 53 }
113 function stringify(obj) { 114 if (typeof obj !== 'object') return obj; 115 116 var cache = [], keyMap = [], index; 117 118 var string = JSON.stringify(obj, function(key, value) { 119 // Let json stringify falsy values 120 if (!value) return value; 121 122 // If we're a node 123 if (value instanceof Node) return '[ Node ]'; 124 125 // jasmine-given has expectations on Specs. We intercept to return a 126 // String to avoid stringifying the entire Jasmine environment, which 127 // results in exponential string growth 128 if (value instanceof jasmine.Spec) return '[ Spec: ' + value.description + ' ]'; 129 130 // If we're a window (logic stolen from jQuery) 131 if (value.window && value.window === value.window.window) return '[ Window ]'; 132 133 // Simple function reporting 134 if (typeof value === 'function') return '[ Function ]'; 135 136 if (typeof value === 'object' && value !== null) { 137 138 if (index = cache.indexOf(value) !== -1) { 139 // If we have it in cache, report the circle with the key we first found it in 140 return '[ Circular {' + (keyMap[index] || 'root') + '} ]'; 141 } 142 cache.push(value); 143 keyMap.push(key); 144 } 145 return value; 146 }); 147 return string; 148 }