Skip to content

A very simple formatter for JSON and YAML based on make, jq and yq

License

Notifications You must be signed in to change notification settings

beji/simple-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Formatter

This is a rather basic file formatting tool based on jq, yq and GNU Make that can be used to format YAML and JSON files. Both tools have to be installed for this to actually work.

Installation

  • Grab the simple-formatter.sh from this repo and place it somewhere
  • Make sure that make, jq and yq are installed and available in the PATH

Usage

Pass at least one file that should be formatted simple-formatter.sh ./a/folder/some.json

It will also accept glob patterns like simple-formatter.sh /some/folder/*

This currently handles JSON & YAML, with the help of JQ and YQ.

The number of parallel jobs can be influenced with the JOBS environment variable. It will default to whatever “nproc –all” returns.

Debug output can be enabled by setting the DEBUG environment variable to 1

How does this work?

The bash script uses Makes parallel execution to increase performance. It will create a Makefile with the help of mktemp and then call that with the files given to it.

The makefile will then generate a temporary file for every file to be formatted, run jq/yq on the input file and write the output to the temporary file. It will then move the temporary file to the input file, overriding it in the process.

Can I influence the formatting in any way?

nope

About

A very simple formatter for JSON and YAML based on make, jq and yq

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published