If you are on a Mac you can use the plutil tool on the command line (this comes with the developer tools I believe):
plutil -convert json -o Data.json Data.plist
If you want to just overwrite the existing file, you can omit the -o parameter:
plutil -convert json Data.plist
Answer from Dylan on Stack OverflowIf you are on a Mac you can use the plutil tool on the command line (this comes with the developer tools I believe):
plutil -convert json -o Data.json Data.plist
If you want to just overwrite the existing file, you can omit the -o parameter:
plutil -convert json Data.plist
If you run into issues with "invalid object in plist for destination format", you probably have bytes-like data in the plist, which plutil does not consider serializable to json.
Python has built-in plist support, and we can specify a custom default function to specify what to do when serialization fails (e.g. on bytes). If you don't care about the bytes fields, we can just serialize them as '<not serializable>' with the following python one-liner:
python -c 'import plistlib,sys,json; print(json.dumps(plistlib.loads(sys.stdin.read().encode("utf-8")), default=lambda o:"<not serializable>"))'
This takes the stdin, parses the plist, then dumps it to json. For example, to get current power information for your Mac, you can run:
ioreg -rw0 -c AppleSmartBattery -a | python -c 'import plistlib,sys,json; print(json.dumps(plistlib.loads(sys.stdin.read().encode("utf-8")), default=lambda o:"<not serializable>"))'
and if you wanted to just get the current charging wattage, you could pipe that into jq '.[0].AdapterDetails.Watts'
Videos
» npm install plist-to-json
In my recent (undocumented) adventures with parsing and manipulating shortcuts as dictionaries, I found that I was ending up with a JSON instead of a plist when trying to convert back to a .shortcut file.
The fix? The “Get File Of Type” action, which I had previously only used in place of “Get Contents Of Webpage” for executing JavaScript.
To convert from JSON to Plist, use com.apple.plist as the UTI and the JSON as the input. (Edit: you can also use com.apple.property-list as the UTI; the result is the same.)
To convert from Plist to JSON, use public.json as the UTI and the plist as the input.