Skip to content

Instantly share code, notes, and snippets.

@tyler-boyd
Last active August 29, 2015 14:05
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 tyler-boyd/738383d9fb19812c84d8 to your computer and use it in GitHub Desktop.
Save tyler-boyd/738383d9fb19812c84d8 to your computer and use it in GitHub Desktop.
require 'json'
first = JSON.parse File.read 'first.json'
second = JSON.parse File.read 'second.json'
third = JSON.parse File.read 'third.json'
categories = []
first['filterElementCommands'].each_with_index do |top_level_category_info, index|
top_category = { info: top_level_category_info }
top_category[:parents] = []
second[index]['filterElementCommands'].each_with_index do |second_level_category_info, index|
second_category = { info: second_level_category_info }
second_category[:parents] = [top_category]
second_category_children = third[index]['filterElementCommands']
if second_category_children.any?
second_category_children.each_with_index do |third_level_category_info, index|
third_category = { info: third_level_category_info }
third_category[:parents] = [top_category, second_category]
categories << third_category
end
else
categories << second_category
end
end
end
File.open('output.json', 'w') { |f| f << JSON.dump(categories) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment