7 examples of 'json string to array' in JavaScript

Every line of 'json string to array' 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
3function convertStringToArray(string) {
4 let array = [];
5 try {
6 array = JSON.parse(string);
7 } catch (err) {
8 // Assume is just a string (single url)
9 if (string) {
10 array = [string];
11 }
12 }
13 return array;
14}
109export function listFromJSON(json: NodeJSON[] | string): Node[] {
110 if (typeof json === "string")
111 return JSON.parse(json, listReviver);
112 return json.map((m) => fromJSON(m));
113}
26export function fromJSON(json: ValueJSON): Value {
27 if (json === null)
28 return undefined;
29 if (isNestedContentValue(json))
30 return json.map(NestedContentValue.fromJSON);
31 if (isArrayValue(json))
32 return valuesArrayFromJSON(json);
33 if (isMapValue(json))
34 return valuesMapFromJSON(json);
35 return json;
36}
92function fromJSON(json) {
93 var classes = Class._classes,
94 mathClasses = Mathf._classes;
95
96 if (typeof(json) !== "object") {
97 return json;
98 } else if (mathClasses[json._className]) {
99 return Mathf.fromJSON(json);
100 } else if (classes[json._className]) {
101 return Class.fromJSON(json);
102 } else {
103 return json;
104 }
105
106 return null;
107}
38function arrayFrom(json) {
39 var queue = [], next = json;
40 while (next !== undefined) {
41 if ($.type(next) == "array")
42 return next;
43 if ($.type(next) == "object") {
44 for (var key in next)
45 queue.push(next[key]);
46 }
47 next = queue.shift();
48 }
49 // none found, consider the whole object a row
50 return [json];
51}
15function arrayParser(json) {
16 var result = '[';
17 for(var i=0;i
80export function fromJson (json) {
81 return isString(json) ? JSON.parse(json) : json
82}

Related snippets