Settings

Theme

Show HN: Flatito, grep for YAML and JSON files

github.com

65 points by ceritium 2 years ago · 24 comments · 1 min read

Reader

It is a kind of grep for YAML and JSON files. It allows you to search for a key and get the value and the line number where it is located.

I created this tool because I sometimes struggle to find specific keys in typical i18n rails yamls. In the views, you don't always have the whole key, but it is extrapolated from the context. I am sure there are other use cases; I hope you find it useful.

Cheers!

ratrocket 2 years ago

This looks cool!

It doesn't do quite the same thing, but a tool I've had good luck with for quick-n-dirty grepping of JSON is gron:

https://github.com/tomnomnom/gron

(which I'm sure I learned about from a thread like this on HN...)

It sort of "flattens out" your JSON to allow you to do whatever you want to it (grepping, for one thing!). Then you can even turn gron's output back into JSON with `ungron`.

Maybe someone will find it a useful toolbox addition, much like the Flatito looks to be!

dimatura 2 years ago

So I see that the name is derived from an esperanto word (apparently meaning "flatter") but in spanish it would also mean a small burp ("flato" being an informal term for burp). Which I still like as a name ;)

  • elondaits 2 years ago

    In Argentina a “flato” is a flatulence, and flatito would mean a little fart.

  • avidphantasm 2 years ago

    My brain saw “fellatio” at first.

  • eddd-ddde 2 years ago

    It's funny being a native Spanish speaker, and seeing other Spanish speakers talk about words you have never ever heard of before.

    • dimatura 2 years ago

      Seems like it's less universal than I thought, and has other meanings (but related to flatulence) in other countries than my own.

  • ceritiumOP 2 years ago

    Hi! Author here! I am spanish, flato means that, but it's also that pain in the side of the belly when you are running.

    • dimatura 2 years ago

      ha, that's funny. Now that you mention it I've heard this. In my case I was referring to Chilean spanish.

    • autoexec 2 years ago

      Is there an English word for that?

      • montag 2 years ago

        Colloquially just sideache, AFAIK.

        • JNRowe 2 years ago

          I always enjoy these side diversions, because they're full of "Huh, WTFs". In English I'd never heard anyone call it anything but "a stitch"¹ colloquially or ETAP as an actual condition, but sure enough side ache features in the list of alternatives on Wikipedia.

          Oddly, Wiktionary has an article for sideache² and a link to that page if you look for side stitch. Makes me curious how often that is the case now. [/me sniped]

          ¹ https://en.wikipedia.org/wiki/Side_stitch

          ² https://en.wiktionary.org/wiki/sideache

al_borland 2 years ago

I usually have to use JMESPath queries semi-regularly. Every time I do it feels like I'm starting over for the first time. I'd love something that made more sense to me, but in most cases I'm stuck with what I have due to restrictions on what I can use at work.

mutant 2 years ago

This till doesn't give any context about the keys context, what's the full path of the key? That's critically important.

gxonatano 2 years ago

This is the kind of thing Nushell is already really good at.

account-5 2 years ago

Is this different from yq?

  • ceritiumOP 2 years ago

    Hi, I didn't know about yq until now; as far as I can see, it seems to allow complex queries and manipulations and handle more formats. Flatito, on the contrary, only handles YAML and JSON. It can look in a whole directory, and most importantly for me, it shows the line number needed to locate the value.

Yasuraka 2 years ago

What I often use to just get the full key paths is yq (https://github.com/mikefarah/yq), piping into grep when necessary

  yq -o=props <file>
e.g.

  kind = Ingress
  metadata.name = hello
  spec.rules.0.host = localhost
  spec.rules.0.http.paths.0.pathType = ImplementationSpecific
  spec.rules.0.http.paths.0.backend.service.name = hello
  spec.rules.0.http.paths.0.backend.service.port.number = 80
The one drawback I've encountered so far are multi-doc files - yq can certainly handle those, but you have to script the loop yourself.
llimllib 2 years ago

related project, gron: https://github.com/tomnomnom/gron

    ▶ gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | fgrep "commit.author"
    json[0].commit.author = {};
    json[0].commit.author.date = "2016-07-02T10:51:21Z";
    json[0].commit.author.email = "mail@tomnomnom.com";
    json[0].commit.author.name = "Tom Hudson";
  • wewtyflakes 2 years ago

    Looks neat, but what happens if a JSON key has a value like "foo.bar" or "foo[0]", etc. Does the textual response escape them?

    • matja 2 years ago

      Yes:

          json = {};
          json["foo.bar"] = true;
          json["foo[0]"] = true;

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection