deweller / switchaudio-osx

Change the audio source for Mac OS X from the command line.
Other
1.19k stars 88 forks source link

‘-a -f json’ doesn't output proper JSON, just separate lines of JSON objects #38

Closed decadent closed 1 year ago

decadent commented 2 years ago

If I call SwitchAudioSource -a -f json, I get separate lines of JSON for each device. However the output as a whole isn't valid JSON, so I can't just decode it in my language—I have to process each line separately. Perhaps it would be better if SwitchAudioSource output the results as an array instead. Of course, this would be a breaking change, but I'd say that ‘json output’ suggests that it can be just decoded all at once, so the fix is justified.

For that, it should be enough to wrap the output in [ and ], and to separate the lines with commas. But I'm not any good at C, so would probably find ways to mess this up.

One thing to look out for is, the JSON spec doesn't allow a comma after the last element of an array (or an object).

deweller commented 1 year ago

Agreed that JSON would have probably been better. But we'll go with jsonl for now.