Forrest logo
back to the cat tool

ajson:tldr:d0404

ajson: Read JSON from `stdin` and execute a specified JSONPath expression.
$ cat ${filename-json} | ajson '${$--json[?(@-path)]}'
try on your machine

This command involves two parts: cat ${filename-json} and ajson '${$--json[?(@-path)]}'.

  1. cat ${filename-json}:

    • cat is a command used to concatenate and display the content of files.
    • ${filename-json} is a variable representing the name of a file in JSON format. The ${} syntax is used to access the value of the variable.
    • So, this part reads the content of the file named ${filename-json} using cat command.
  2. ajson '${$--json[?(@-path)]}':

    • ajson is a command-line tool used for processing and manipulating JSON data.
    • '${$--json[?(@-path)]}' is an argument provided to the ajson command. It is a JSONPath expression enclosed in single quotes.
      • ${$} represents the entire JSON document.
      • --json[?(@-path)] is a JSONPath filter expression. It filters the JSON properties that have a "path" field.
    • So, this part uses the ajson command to filter and display JSON properties that have a "path" field from the JSON data received from the previous cat command.

In summary, the command reads the content of a JSON file and then filters and displays only the JSON properties that have a "path" field.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the cat tool