Skip to content
Advertisement

Decode a base64 encoded JSON string generated from JavaScript in Python

Take this base64-encoded JSON string generated from JavaScript using JSON.stringify and btoa:

JavaScript

I’m trying to decode it from Python. I’m doing:

JavaScript

I’m getting a UnicodeDecodeError:

JavaScript

What is the right way to properly decode this in Python?

Note: I’m using base64 encoding so this can be safely passed as an URL query string parameter.

Thanks!

Advertisement

Answer

You can also do in JavaScript

JavaScript

though I think btoa works on just the extended ascii table, not all unicode characters.

Then in Python

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement