BBEdit Text Filter to format JSON
First attempt at writing a BBEDit Text Filter
Created:
I always wondered how some of the BBEdit features (like Text Filters) worked.
The model of operation is quite simple:
- you have a script that takes input from the standard input
(
stdin
) and run the program over that input. - you save this script (could be any language, I went with Python
here.) under
~/Library/Application Support/BBEdit/Text Filters
. I named the following scriptJSON Format.py
; yes - space and all because that’s what shows up in BBEdit’s menu like this:
{: width=“500”}
I open up a JSON file and run this option, to have it neatly formatted. Voilà!
#!/usr/bin/env python3
"""
JSON Format.py
This BBEdit TextF Filter formats a json file in the bbedit buffer
using python's json module
Pradeep Gowda
2022-10-23
"""
import json
import sys
= sys.stdin.read()
text print(json.dumps(json.loads(text), indent=2))
Commit the ~/Library/Application Support/BBEdit/
directory to git and you can use them from different mac machines
running BBEdit:
cd ~/Library/Application Support/BBEdit/
git init
git push ..blah..
You may want to exclude the Notes.bbnotebookd
directory
which contains the “Notes”s.