title: How to filter map content by path
body: <p>I want to select paths of a deeply nested map to keep.</p>
  <p>For example:</p>
  <pre class="lang-clj prettyprint-override"><code>{:a 1
   :b {:c [{:d 1 :e 1} 
           {:d 2 :e 2}]
       :f 1}
   :g {:h {:i 4 :j [1 2 3]}}}
  </code></pre>
  <p>I want to select by paths, like so:</p>
  <pre class="lang-clj prettyprint-override"><code>(select-paths m [[:a] 
                   [:b :c :e]
                   [:b :f]
                   [:g :h :i]])
  </code></pre>
  <p>This would return</p>
  <pre class="lang-clj prettyprint-override"><code>{:a 1
   :b {:c [{:e 1}
           {:e 2}]
       :f 1}
   :g {:h {:i 4}}}
  </code></pre>
  <p>Essentially the same as Elasticsearch's <code>fields</code> parameter. The format of the paths argument can be something else, this is just the first idea.</p>
  <p>I tried two different solutions</p>
  <ol>
  <li>Go through the entire map and checking if the full path of the current element is in the given paths. I can't figure out how to handle lists of maps so that they are kept as lists of maps.</li>
  <li>Creating <code>select-keys</code> statements from the given paths but again I run into problems with lists of maps - and especially trying to resolve paths of varying depths that have some common depth.</li>
  </ol>
  <p>I looked at spectre but I didn't see anything that would do this. Any <code>map</code> or <code>postwalk</code> based solution I come up with turns into something incredibly convoluted at some point. I must be thinking about this the wrong way.</p>
  <p>If there's a way to do this with raw json, that would be fine as well. Or even a Java solution.</p>