Wallet pass: JSON with binary content/unknown encoding

I am working on an App which is capable of opening Wallet passes (.pkpass files). While I can now open most of my testing passes (used/expired boarding passes / tickets / etc. I found in my mails), one specific pass fails to open: My subway card. It is rather old; I have it in the wallet for quite some time now. When I uncompress the .pkpass file (exported from the Wallet), I will get a JSON file which cannot be opened properly. If I do e.g. less pass.json, this is what I see:

If I open the same file in XCode, this is what I see:

Interestingly, when I open the file using the quick preview in Finder (space), or open file properties in Finder, I will get a valid and clean preview as well. Also, the pass was exported from my iOS wallet, so the file must be valid.

This leads me to believe that this file is using some kind of encoding which cannot be displayed correctly in e.g. less. I tried opening the file using BBedit, but no matter which encoding I pick, I will always get garbage.

Can anyone tell me which kind of encoding/file format this is, so I can implement a proper method of opening/parsing this?

Can anyone tell me which kind of encoding/file format this is, so I can implement a proper method of opening/parsing this?

As far as I see the content shown with less, it seems to be a JSON text written in UTF-32LE. Have you tried to read the content of the file as String using .utf32LittleEndian?

Thanks for the hint. I am using QT in my app, and before I did:

 QJsonParseError jsonErr;
 QByteArray contents = file.readAll();
 auto doc = QJsonDocument::fromJson(contents, &jsonErr);

Now after your hint I was able to do this, which seems to be working:

QJsonParseError jsonErr;
QByteArray contents = file.readAll();
QString utf32String = QString::fromUcs4((const uint*)contents.data());

auto doc = QJsonDocument::fromJson(utf32String.toUtf8(), &jsonErr);

It still won't parse, because the JSON actually contains a trailing comma, which the Wallet app seems to ignore, but QJsonDocument not. What a pity, but thats another story. However the data seems to be readable now, when I dump the utf32String, I'll get:

There is still some weird characters at the end, not sure what they are. (I had to add this as screenshot, because it would not add a reply here with those invalid characters)

Is there any way I can detect that this is UTF-32 instead of UTF-8, other than the normal parsing failing & trying to parse again?

Wallet pass: JSON with binary content/unknown encoding
 
 
Q