Skip to content

rafa852/python-json-via-jinja2-render

 
 

Repository files navigation

About

Very simple script to get json input, pass it via Jinja2 template to get the output.

Why? Sometimes I got some simple json file and I want to process it into something easier to read, for example text file or html.

Other tools usually do too much already, like extra connecting to internet idk why...

Known limitations

  • not providing pip package, I'm too lazy and this is too simple to package it anyway.... or docker, yeaaaaaaahhh ;)
  • template used is TOTALLY dependent on json file used as input, see examples

Requirements

  • pretty sure it requires python
  • may require Jinja2

Usage

render.py --help

Examples

AWS ECR security scan output

Plain text short

python render.py \
  -i examples/aws_ecr_scan_result.json \
  -t templates/aws_ecr_scan_result_plaintext_short.j2 \
  -o examples/aws_ecr_scan_result_plaintext_short.txt

Plain text long

python render.py \
  -i examples/aws_ecr_scan_result.json \
  -t templates/aws_ecr_scan_result_plaintext_long.j2 \
  -o examples/aws_ecr_scan_result_plaintext_long.txt

HTML

This is a bit more useful :)

python render.py \
  -i examples/aws_ecr_scan_result.json \
  -t templates/aws_ecr_scan_result_html.j2 \
  -o examples/aws_ecr_scan_result_html.html

Fully rendered output here.

Docker

cat examples/aws_ecr_scan_result.json \
| docker run -v $(pwd)/templates/:/app/templates:ro -i quay.io/kaszpir/python-json-via-jinja2-render -t templates/aws_ecr_scan_result_html.j2 \
> output.html

or:

docker run \
    -v "$(pwd)/templates/:/app/templates:ro" \
    -i quay.io/kaszpir/python-json-via-jinja2-render \
        -t templates/aws_ecr_scan_result_html.j2 \
        <examples/aws_ecr_scan_result.json \
        >output.html

Running in container with custom templates

  • Create my_template dir with desired template
  • write my_template/custom.j2 file which is tailored to your json input files
  • Run command to get output to stdout:
cat examples/aws_ecr_scan_result.json \
| docker run -v $(pwd)/my_template/:/app/templates:ro -i quay.io/kaszpir/python-json-via-jinja2-render -t templates/custom.j2 \
> output.html

About

Get json input, pass it via Jinja2 template and render it

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 71.9%
  • Python 17.3%
  • Shell 6.5%
  • Dockerfile 4.3%