Try this:
> (use 'clojure.pprint)
> (def stuff '({:dim :time, :body "20 minutes from now", :value {:type "value", :value "2016-08-03T10:50:56.000+05:30", :grain :second, :values ({:type "value", :value "2016-08-03T10:50:56.000+05:30", :grain :second})}, :start 21, :end 40}))
We use the "pretty print" function pprint
to get a nicely-nested output for the data structure:
> (pprint stuff)
({:dim :time,
:body "20 minutes from now",
:value
{:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second,
:values
({:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second})},
:start 21,
:end 40})
So we have a list of one item, which is map of keys :dim :body :value :start and :end. The value for the :value
key is another map of keys :type, :value, :grain, :values.
So, to un-nest this,
(pprint (first stuff))
{:dim :time,
:body "20 minutes from now",
:value
{:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second,
:values
({:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second})},
:start 21,
:end 40}
> (pprint (:value (first stuff)))
{:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second,
:values
({:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second})}
> (pprint (:values (:value (first stuff))))
({:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second})
You could also use the thread-first macro ->
as follows:
> (pprint (-> stuff first :value :values))
({:type "value",
:value "2016-08-03T10:50:56.000+05:30",
:grain :second})
so that the original nested structure stuff
flows through the functions first
, :value
, and :values
(in that order).