Every line of 'string to json php' 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.
40 function getJsonString(obj) { 41 try { 42 return JSON.stringify(obj); 43 } catch(e) {} 44 return ""; 45 }
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
9 function toJson(string) { 10 try { 11 return JSON.parse(string) 12 } catch (err) { 13 return string 14 } 15 }
60 function 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 }