How to Decode base64 Encoded with Python ?

Pelin R. Kuran
Personal Work Revision
2 min readOct 28, 2020

--

In this article we will be trying to decode base64 encoded string object of a JSON file with the great Python also as a bonus I will show how to get your JSON data in a web service.

Before starting I would like to say that Python is a great tool for many things that you can think of developing. Especially with Linux so that with Mac OS it works almost flawless. If you are interested in how broad Python is or you want to gain general knowledge about it, I suggest you to watch this video called What is Python? Why Python is So Popular? published by Programming with Mosh.

So, if you are ready let’s start decoding!

1. Import the Important

After installing the modules and adjusting necessary things you should be able to import all the followings.

2. Get the JSON

Now if your JSON is on your computer, you need to get it. If you don’t know how to do it just see here. If it is a web service then you can assign it to a variable, like

3. Finally Conquer the Base64 Encoded

Here be careful that I am decoding a string value of the object, so it should look like this,

Now all you need to do is decode the message,

and all done!

Note that sometimes you need to point the index, if especially you are working with one objected JSON file otherwise you may have some trouble getting data.

Sometimes we have nested objects in JSON file, in this case what you decoded is an object.

The assigned variable will be a JSON object. Based on this logic you can reach your object values by that notation:

json_str["objectName"]["objectValue"]- or -json_str.objName.objValue;- or -json_str.objectName.["objectValue"]

I hope you liked what you read!

Work hard, have fun, make history. — Jeff Bezos

Pelin R. Kuran

Undergraduate Information Systems Engineer

--

--