Freelance iOS Developer, Rapidly Aging Punk

Fixing Invalid Parameters in BBEdit Text Filters

Feb 11, 2015 at 01:32PM

This blog post from Crisp is the only example of a JSON Pretty Print BBEdit text filter I could find and unfortunately I was only able to get it to work about 25% of the time – the other 75% I would get this error message from BBEdit:

Invalid parameters were detected for an operation (MacOS Error code: -50)

There's not a lot going on in the script so I banged my head against it until I figured out how to fix it: Aggressively insisting on UTF-8 string encoding. Here's the modified script:

import fileinput
import json

if __name__ == "__main__":
  json_string = ''
  for line in fileinput.input():
    json_string = json_string + ' ' + line.strip()
  json_object = json.loads(json_string.encode('utf-8'))
  print json.dumps(json_object, sort_keys=True, indent=2).encode('utf-8')