I've tried to look for an answer to this on various sites including seeing some seemingly relevant answers on here, however everything I have tried hasn't worked. I'm trying to learn Clojure by making a simple JSON data analytics program.
I have the following example data (taken by using Cheshire to parse a JSON file, using slurp and parse-string):
({:id "0",
:data [{:name "item1 x 1", :price {:GBP 9.99}} {:name "Delivery", :price {:GBP 3.49}}],
:date {:date "2014-01-12T01:21:28.000Z"},
:total {:GBP 1,
{:id "1",
:data [{:name "item2 x 1", :price {:GBP 9.99}}
{:name "item3 x 1", :price {:GBP 9.99}}
{:name "item4 x 1", :price {:GBP 9.99}}
{:name "Admin", :price {:GBP 3.49}}],
:date {:date "2013-01-12T07:37:04.000Z"},
:total {:GBP 2},
{:id "2",
:data [{:name "item6 x 1", :price {:GBP 9.99}}
{:name "item7 x 1", :price {:GBP 9.99}}
{:name "item4 x 2", :price {:GBP 9.99}}
{:name "item1 x 1", :price {:GBP 9.99}}
{:name "item2 x 1", :price {:GBP 9.99}}
{:name "Admin", :price {:GBP 3.49}}],
:date {:date "2012-01-15T13:29:54.000Z"},
:total {:GBP 3},
{:id "3",
:data [{:name "item8 x 1", :price {:GBP 9.99}}
{:name "item4 x 1", :price {:GBP 9.99}}
{:name "item5 x 1", :price {:GBP 9.99}}
{:name "item9 x 1", :price {:GBP 9.99}}
{:name "item4 x 1", :price {:GBP 9.99}}
{:name "Admin", :price {:GBP 3.49}}],
:date {:date "2014-01-17T06:22:23.000Z"},
:total {:GBP 4},
})
I believe this is a persistent vector of maps or some other data structure (I'm struggling with data types in clojure). I'm trying to extract specific data from this to answer analytics questions such as which item was ordered most frequently, how much money was made on this day etc.
My initial problem is simply trying to extract the item values from the :name keys in this data.
I've tried using map :data which isolates the data to just the item names and prices, and using type then shows that this is a lazy sequence. However, I'm then struggling to actually get the data from the name keys (e.g. item1 x 1). I've tried using the map function and the get-in function to no avail. I think this is due to the way the data is held so any explanation of this would be greatly appreciated!
This is what I'm currently stuck on although if anyone does want to help me solve the greater problem of then getting the most frequent orders that would be awesome!
Thank you :)