Created
November 27, 2016 13:33
-
-
Save kiloreux/5eada9bf379d8fdaab9d56aeba8996a9 to your computer and use it in GitHub Desktop.
Turn JSON Object to Ruby hashes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
formatJR(obj, depth = 0) { | |
let out ="" | |
let addition = "" | |
let steps = [] | |
let type = typeof(obj) | |
switch(type) { | |
case "string": | |
case "boolean": | |
case "number": | |
out += JSON.stringify(obj) | |
break | |
case "object": | |
let isArray = Array.isArray(obj) | |
debugger | |
out+=" {\n" | |
depth += 1 | |
for (let key in obj) { | |
out += " ".repeat(depth) | |
if(!isArray) { | |
out += `:${key}` + " =>" | |
} | |
if(Array.isArray(obj[key])) { | |
out += JSON.stringify(obj[key]) + ",\n" | |
} | |
else { | |
out += this.formatValue(obj[key], depth) + ",\n" | |
} | |
} | |
depth-=1 | |
out += " ".repeat(depth) + "}" | |
break | |
default: | |
console.log("unknown type for formatting", type, obj) | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment