Last active
August 29, 2015 14:05
-
-
Save tyler-boyd/738383d9fb19812c84d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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