Skip to content

Instantly share code, notes, and snippets.

@drakemccabe
Last active January 15, 2016 21:45
Show Gist options
  • Save drakemccabe/3ec176ca71115bc40e2d to your computer and use it in GitHub Desktop.
Save drakemccabe/3ec176ca71115bc40e2d to your computer and use it in GitHub Desktop.
Format JSON file
require "json"
require "pry"
file_raw = File.read("./keywords.json")
file = JSON.parse(file_raw)
counter = 1
file["results"]["Keywords"].each_with_index do |keyword, index|
file["results"]["Keywords"][index] = { keyword["url"].split('/'[-1]).last => keyword }
end
File.open("./keywords1.json", "w") do |f|
f << (JSON.pretty_generate(file))
end
file_raw = File.read("./keywords1.json")
file = JSON.parse(file_raw)
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment