BBEdit Text Filter to format JSON

First attempt at writing a BBEDit Text Filter

Created: by Pradeep GowdaUpdated:Aug 01, 2024Tagged: json · bbedit · python · code .

I always wondered how some of the BBEdit features (like Text Filters) worked.

The model of operation is quite simple:

bbedit menu with this text filter{: 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

text = sys.stdin.read()
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.

See also: BBEdit, and jsonfmt