This also fixes an issue where some console output for packages I was installing was creating invalid JSON because it contained single-quotes.
pkgin always returns 0 so can't be used to tell if the install or remove worked. Instead this just queries the installed packages after performing an operation.