Skip to content

use formatted chunk i.e. say "join-lines" etc. #27

Description

@goyalyashpal

hi again! as always, thank for such a wonderful tool.

just today i stumbled upon a use case where it might make sense to be able to use a chunk i.e. @< ... @> but in a single line form, i.e. such that all the newlines in the chunk's definition are removed.

this can be given name of:

  • --as-single-line: direct, obvious, understandable
  • --super-trimmed: as it's just trimming the terminal spaces: leading, trailing, and newlines
  • --minify: might be a bit misleading, as minify involves removing spaces within lines too, which is NOT the scope of this issue

example use case:

These chunks contain filters in human-readable (i.e. pretty printed) form

@d filter1 @{
reduce(
  .packages[]
  | select (.id | test("^Microsoft\\.VisualStudio\\.Component\\.Windows1[01]SDK\\..*") )
  | {
      ( .id 
        | split(".")[-1] 
        | select(tonumber?) 
      ): .id
    }
) as $item ({}; . + $item)
@}

@d filter2 @{ ... @}
@d filter3 @{ ... @}

----

Save filters to ``.jq`` files for standalone use with ``jq`` CLI application

@o filter1.jq @{< filter1 @>@}
@o filter2.jq @{< filter2 @>@}
@o filter3.jq @{< filter3 @>@}

-----

Use the filter in a ``.jqpg`` (jq playground) file for quick interactive use

@o my_jq_based_application.jqpg @{

jq @< --as-single-line filter1 @>
> output1.json
$ cat input.json

jq @< --as-single-line filter2 @>
> output2.json
$ cat output1.json

jq @< --as-single-line filter3 @>
> final_output.json
$ cat output2.json

@}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions