← All projects
Project record1 mention
Originally shared on Hacker News

schmuck

A Ruby library that turns strings into procs for traversing deeply nested data structures like JSON responses. It works as a Ruby block with map/find, lets you call Ruby methods from it, does not auto-flatten arrays, and raises on nil by default unless using the & operator.

Last shared
01 / The problem

What it addresses

Nested flat_map chains made code unreadable just to fetch a simple value from deeply nested structures like JSON responses.

02 / Source history

Shared over time

Each entry reflects what was shared on that date. Details may have changed since then.

  1. schmuck

    A Ruby library that turns strings into procs for traversing deeply nested data structures like JSON responses. It works as a Ruby block with map/find, lets you call Ruby methods from it, does not auto-flatten arrays, and raises on nil by default unless using the & operator.

    Problem: Nested flat_map chains made code unreadable just to fetch a simple value from deeply nested structures like JSON responses.

    Posted by @samleb34 · Original source ↗

    Story title · @samleb34 · · Source ↗

    Show HN: String#to_proc` to Help Traversing JSON

    Submitted URL · @samleb34 · · Source ↗

    https://github.com/samleb/schmuck

    Source text · @samleb34 · · Source ↗

    The idea is to make simple & readable the traversing of deeply nested structures like JSON responses, while staying in Ruby & keeping its flexibility.

    Source text · @samleb34 · · Source ↗

    I was tired of having nested `flat_map` making my code basically unreadable just to fetch a simple value.

    Source text · @samleb34 · · Source ↗

    it's a Ruby block so you can use it with `map`, `find`, etc.