Created
April 25, 2018 16:12
-
-
Save marktellez/181a431b479f617ded40be914c028a0d to your computer and use it in GitHub Desktop.
This file contains 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
{ | |
"product": { | |
"regions": [ | |
{ | |
"vendor-ids": [ | |
2098 | |
], | |
"subcategories": [ | |
{ | |
"attributes": [ | |
{ | |
"attr-type": "prices", | |
"max-price": "$8.40", | |
"name": "Prices", | |
"min-price": "$8.40" | |
}, | |
{ | |
"attr-type": "shipping", | |
"name": "Shipping", | |
"min-price": "$4.24" | |
}, | |
{ | |
"id": "AA9081EC-37A3-43C5-A9D0-9BEC266E77AD", | |
"name": "Colors", | |
"attr-type": "two-color-list", | |
"values": [ | |
{ | |
"hex": [ | |
"#ffffff", | |
"#000000" | |
], | |
"id": "C477A809-40CD-4BB4-9C30-A650B61CBFA8", | |
"name": "White with Black Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#211261" | |
], | |
"id": "379316B4-CCD0-41CA-8B67-C857D2C681E6", | |
"name": "White with Blue Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#00594E" | |
], | |
"id": "E5231B2C-DDD1-4F24-9147-8859428D9084", | |
"name": "White with Green Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#e14504" | |
], | |
"id": "5326761D-EC5E-4D85-878A-64725530D745", | |
"name": "White with Orange Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#e5aaba" | |
], | |
"id": "F1B92AF2-7523-459E-BA76-491C9D941D5A", | |
"name": "White with Pink Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#c20430" | |
], | |
"id": "70AAD8E6-0A49-44B9-86E1-FA7984803FAE", | |
"name": "White with Red Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#dbc657" | |
], | |
"id": "92CE80A4-934B-49BB-9A52-9C37DB51BCDA", | |
"name": "White with Yellow Accents" | |
} | |
] | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "11 oz" | |
} | |
], | |
"name": "Sizes", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Ceramic" | |
} | |
], | |
"name": "Material", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Full wrap with border" | |
} | |
], | |
"name": "Image size", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Microwave and dishwasher safe" | |
} | |
], | |
"name": "Care of", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Packaged in a corrugated box which ensures safe drop shipping to your customers." | |
} | |
], | |
"name": "Packaging", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "4 days" | |
} | |
], | |
"name": "Production time", | |
"attr-type": "list" | |
} | |
] | |
} | |
], | |
"name": "US & Canada", | |
"desc": "Shipping to US & Canada from US facilities.\n" | |
}, | |
{ | |
"vendor-ids": [ | |
2098 | |
], | |
"subcategories": [ | |
{ | |
"attributes": [ | |
{ | |
"attr-type": "prices", | |
"max-price": "$8.40", | |
"name": "Prices", | |
"min-price": "$8.40" | |
}, | |
{ | |
"attr-type": "shipping", | |
"name": "Shipping", | |
"min-price": "$4.24" | |
}, | |
{ | |
"id": "AA9081EC-37A3-43C5-A9D0-9BEC266E77AD", | |
"name": "Colors", | |
"attr-type": "two-color-list", | |
"values": [ | |
{ | |
"hex": [ | |
"#ffffff", | |
"#000000" | |
], | |
"id": "C477A809-40CD-4BB4-9C30-A650B61CBFA8", | |
"name": "White with Black Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#211261" | |
], | |
"id": "379316B4-CCD0-41CA-8B67-C857D2C681E6", | |
"name": "White with Blue Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#00594E" | |
], | |
"id": "E5231B2C-DDD1-4F24-9147-8859428D9084", | |
"name": "White with Green Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#e14504" | |
], | |
"id": "5326761D-EC5E-4D85-878A-64725530D745", | |
"name": "White with Orange Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#e5aaba" | |
], | |
"id": "F1B92AF2-7523-459E-BA76-491C9D941D5A", | |
"name": "White with Pink Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#c20430" | |
], | |
"id": "70AAD8E6-0A49-44B9-86E1-FA7984803FAE", | |
"name": "White with Red Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#c20430" | |
], | |
"id": "70AAD8E6-0A49-44B9-86E1-FA7984803FAE", | |
"name": "White with Neon Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#c20430" | |
], | |
"id": "70AAD8E6-0A49-44B9-86E1-FA7984803FAE", | |
"name": "White with Gold Accents" | |
}, | |
{ | |
"hex": [ | |
"#ffffff", | |
"#dbc657" | |
], | |
"id": "92CE80A4-934B-49BB-9A52-9C37DB51BCDA", | |
"name": "White with Yellow Accents" | |
} | |
] | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "11 oz" | |
} | |
], | |
"name": "Sizes", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Ceramic" | |
} | |
], | |
"name": "Material", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Full wrap with border" | |
} | |
], | |
"name": "Image size", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Microwave and dishwasher safe" | |
} | |
], | |
"name": "Care of", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "Packaged in a corrugated box which ensures safe drop shipping to your customers." | |
} | |
], | |
"name": "Packaging", | |
"attr-type": "list" | |
}, | |
{ | |
"values": [ | |
{ | |
"name": "4 days" | |
} | |
], | |
"name": "Production time", | |
"attr-type": "list" | |
} | |
] | |
} | |
], | |
"name": "EU", | |
"desc": "Shipping to EU from EU facilities.\n" | |
} | |
] | |
} | |
} | |
This file contains 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' | |
json = JSON.parse(File.read('./example.json')) | |
def collect_colors(json) | |
json["product"]["regions"].flat_map {|region| region["subcategories"].flat_map {|sc| sc["attributes"]}}. | |
#reduce([]) {|acc, json| acc.push(json.select {|json| json["name"] == "Colors" }) if acc.select {|colors| colors }} | |
select {|attrs| attrs["name"] == "Colors" } | |
end | |
colors = collect_colors(json) | |
p colors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment