Convert JSON to ruby hash

Developer
Size
2,000 Kb
Views
42,504

How do I make an convert json to ruby hash?

What is a convert json to ruby hash? How do you make a convert json to ruby hash? This script and codes were developed by Zachary Olson on 10 November 2022, Thursday.

Convert JSON to ruby hash Previews

Convert JSON to ruby hash - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Convert JSON to ruby hash</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Convert JSON to ruby hash</h1>
<p>(Work in progress)</p>
<textarea id="input"></textarea>
<button onclick="convert()">Convert</button>
<textarea id="output"></textarea> <script src='http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Convert JSON to ruby hash - Script Codes CSS Codes

textarea { width: 100%; height: 10em; box-sizing: border-box;
}
button { float: right; width: 10em;
}

Convert JSON to ruby hash - Script Codes JS Codes

var convert = function(){ document.querySelector("#output").value = convertRecur(JSON.parse(document.querySelector("#input").value,0));
}
var convertRecur = function(obj, spaces, ignoreKeys){ var spacer = " "; var ret = ""; _.each(obj, function(v,k){ if(typeof(v)=="string") ret+=spacer.substr(0, spaces)+(ignoreKeys ? "" : ":"+k+" => ")+"\""+v+"\","+"\n"; else if(typeof(v)=="number") ret+=spacer.substr(0, spaces)+(ignoreKeys ? "" : ":"+k+" => ")+v+","+"\n"; else if(typeof(v)=="object") { if(v.length) { ret+=spacer.substr(0, spaces)+(ignoreKeys ? "" : ":"+k+" => ")+"["+"\n"; ret+=convertRecur(v, spaces+2, true)+"\n"; ret+=spacer.substr(0, spaces)+"],"+"\n"; } else { ret+=spacer.substr(0, spaces)+(ignoreKeys ? "" : ":"+k+" => ")+"{"+"\n"; ret+=convertRecur(v, spaces+2)+"\n"; ret+=spacer.substr(0, spaces)+"},"+"\n"; } } }); ret = ret.substr(0,ret.lastIndexOf(",")); return ret;
}
Convert JSON to ruby hash - Script Codes
Convert JSON to ruby hash - Script Codes
Home Page Home
Developer Zachary Olson
Username zacharyolson
Uploaded November 10, 2022
Rating 3
Size 2,000 Kb
Views 42,504
Do you need developer help for Convert JSON to ruby hash?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Zachary Olson (zacharyolson) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!