Skip to content

Instantly share code, notes, and snippets.

@jgarber
Created August 27, 2013 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgarber/6349042 to your computer and use it in GitHub Desktop.
Save jgarber/6349042 to your computer and use it in GitHub Desktop.
PIAS fast-forward
require 'json'
def replace_json(node, &replacement_action)
case node
when Hash
node.each_value do |item|
yield item
replace_json(item, &replacement_action)
end
when Array
node.each do |item|
yield item
replace_json(item, &replacement_action)
end
end
end
if STDIN.tty?
puts 'cat pias-input.json | #{$0} > pias-output.json'
else
data = JSON.parse(STDIN.read)
replace_json(data) do |node|
if node.is_a? Hash
if duration = node["duration"]
node["duration"] = duration / 10
end
end
end
puts JSON.pretty_generate(data)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment