# An introduction to handling nested data with Specter

**URL:** https://clojureverse.org/t/an-introduction-to-handling-nested-data-with-specter/8456
**Category:** Blogs
**Tags:** intermediate, beginner
**Created:** [December 22, 2021, 6:04pm UTC](https://clojureverse.org/t/an-introduction-to-handling-nested-data-with-specter/8456 "2021-12-22T18:04:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Futurile](https://clojureverse.org/letter_avatar_proxy/v4/letter/f/9de0a6/32.png) [@Futurile](https://clojureverse.org/u/Futurile)
#### Post date: [December 22, 2021, 6:04pm UTC](https://clojureverse.org/t/an-introduction-to-handling-nested-data-with-specter/8456/1 "2021-12-22T18:04:36Z")

</div>

Want to be a 🧙 when handling nested data?

[Specter](https://github.com/redplanetlabs/specter) is a library for Clojure/ClojureScript that makes it simple to navigate through and change nested data. It’s a ‘swiss army knife’ for handling complex data structures.

With it you can:

- Query values in a nested structure
- Change each key or value in a nested map
- Change each value in a nested sequence
- Append or prepend values in a nested map or sequence
- Add (or remove) a value at a specific place in a map or sequence

I’ve written a [general introduction to using Specter for navigating, querying and changing nested data](http://www.futurile.net/2021/03/20/specter-nested-data-manipulation-for-clojure/). It’s aimed at beginners/intermediates and works through some different examples.

Specter is amazing, well worth the time to learn it. My article is really just scratching the surface … there are more advanced capabilities to discover! Feedback welcome - maybe use-cases not covered?

---

<div class="post-metadata">

### Author: ![The-Alchemist](https://clojureverse.org/user_avatar/clojureverse.org/the-alchemist/32/4246_2.png) [@The-Alchemist](https://clojureverse.org/u/The-Alchemist)
#### Post date: [December 24, 2021, 4:59pm UTC](https://clojureverse.org/t/an-introduction-to-handling-nested-data-with-specter/8456/2 "2021-12-24T16:59:54Z")

</div>

I’d love to hear some real-world use cases where this came in handy. I haven’t come across any deeply nested structures in a while, and I love hearing war stories. 😉

---

<div class="post-metadata">

### Author: ![mvarela](https://clojureverse.org/user_avatar/clojureverse.org/mvarela/32/1478_2.png) [@mvarela](https://clojureverse.org/u/mvarela)
#### Post date: [January 3, 2022, 7:03am UTC](https://clojureverse.org/t/an-introduction-to-handling-nested-data-with-specter/8456/3 "2022-01-03T07:03:55Z")

</div>

At my previous job, I had to work with measurement data (WebRTC QoS metrics) that needed to be aggregated into a deep hierarchical structure. At the lowest level, there were measurement data, on top of that there were quality of experience estimates for each media stream, then for combined audio-visual quality, and so on, with several end-points to be considered at each level, and metadata for performing root cause analysis when things went south, quality-wise. Flattening this structure didn’t make sense, from the point of view of the computations needed, but handling it with the vanilla Clojure functions would’ve been a nightmare. With Specter, the whole thing boiled down to taking the original structure, sticking it inside a thread-last form, and performing a level-wise calculation with Specter’s `transform` at each step. It turned out to be much clearer and simpler, I think.

Getting to the point that it was comfortable to write the paths did take some time, though.

In my current job I’m using it in simpler cases, but with a similar premise. I have a tree with a couple of levels, and need to update leaves or internal nodes, or sometimes rename keys. I’ve found that for these cases it’s a great tool.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [July 4, 2022, 7:04pm UTC](https://clojureverse.org/t/an-introduction-to-handling-nested-data-with-specter/8456/4 "2022-07-04T19:04:10Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
