Last active
December 15, 2015 02:19
-
-
Save usahg/5186397 to your computer and use it in GitHub Desktop.
quotes nested values in json
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
# problem : | |
# was trying to import a 3D model in a web page in json format for use with threejs : https://github.com/mrdoob/three.js | |
# 3D model was exported from maya using this threejs plugin # https://github.com/mrdoob/three.js/tree/master/utils/exporters/maya | |
# exported json had two problems: | |
# 1. all of it was in one line, i.e no indents | |
# 2. float values inside keys were not quoted i.e stringified. | |
# here's the snippet, it converts the 'bad' json to 'good' ( quoted json ) | |
@parsed = JSON.parse(Rails.root.join("app","assets","javascripts","model.js").read) | |
@parsed.each do |k,v| | |
if @parsed[k].class == Array | |
@parsed[k].collect! { |c| !c.is_a?(String) ? "#{c}" : c } | |
end | |
end | |
p @parsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment