Skip to content

Instantly share code, notes, and snippets.

@Altech
Created October 18, 2013 03:28
Show Gist options
  • Save Altech/7036087 to your computer and use it in GitHub Desktop.
Save Altech/7036087 to your computer and use it in GitHub Desktop.
modify json interactively on Ruby data structure.
#!/usr/bin/env ruby
def modify_json(file_path)
require 'json'
require 'colorize'
require 'pry'
raise "The file is not exist!".red if not File.exists? file_path
json = JSON.parse(File.read(file_path))
puts "json.keys: " + json.keys.join(",")
binding.pry
File.write file_path, json.to_json
puts "The file has updated!".green
end
modify_json(ARGV.first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment