Ask coding questions

← Back to all posts
How do I keep a json file private without having to by the premium plan.
Quackalicious (0)

I'm new here to repl.it and I have been coding in python for a bit. I'm trying to connect my python code with my google API and spreadsheets but I also have a JSON file I need to use for that. I'm pretty sure I have to keep that private but I'm not sure how. Please help this is putting a stop to something I've been working on for a long time.

Comments
hotnewtop
robowolf (435)

I've also tried to use google spreadsheets on repl. Sadly there is no way to conceal a JSON file. What you could do is find some components of the JSON file that you could put in a .env for later use. Another way to do it is obfuscation, which means you could encrypt it (https://qvault.io/2020/02/06/aes-256-cipher-python-cryptography-examples/) and store the encryption in a .env file. Then you can decrypt it when you need to use it. Any methods using a .env cannot be used by other people unless they are in a multiplayer.

Quackalicious (0)

@robowolf Thanks! I'll definitely check out the encryption method!

Coder100 (17018)

You can use first turn the json into one line, and then paste it into a key, like this:

#.env
KEY={"a":"...","b":"..."}

then when you access it, all you have to do is:

import json
import os

print(json.loads(os.getenv("KEY")))
Quackalicious (0)

@Coder100 what do you mean one line. also that method looks like everyone would be able to see the key. I am trying to make it so people can not see the key because it is private.

Coder100 (17018)

Of course not, .env files are literally private to others
https://docs.repl.it/repls/secret-keys
@Quackalicious

Quackalicious (0)

@Coder100 ohhhhh now i see what you mean, okay but still what do you mean turn the json into one line

Quackalicious (0)

@Quackalicious Okay I am a certified idiot, I finally understand, sry if I was a nuisance.

Quackalicious (0)

@Coder100 wait, I think I'm still an idiot sry, how do I put the key into the encrypter. like lets say my key was ababa. what would i do for that

Coder100 (17018)

ur .env looks like this:

KEY=ababa

and you access it like this:

import os
key = os.getenv("KEY") # key is now ababa

@Quackalicious

Quackalicious (0)

So when i try and print the key in main.py its supposed to say None right?

Coder100 (17018)

no, because you are the owner so you can access .env @Quackalicious

Quackalicious (0)

@Coder100 okay so look I pasted the exact same code into my reply and when I tried to print the variable key like the key not KEY, it came up as none

Coder100 (17018)

invited you to the working repl @Quackalicious

Quackalicious (0)

@Quackalicious I literally copied and pasted what you ha in your repl into mine and it doesn't work https://replit.com/@Quackalicious/Test#main.py

Coder100 (17018)

well of course, if you aren't the owner you can't access .env, meaning others can't run the program at all @Quackalicious

Quackalicious (0)

@Coder100 no but I mean I put the code into my own thing which I am the owner of. I feel like I'm bothering you too much, sry. I'll find out how to do it myself.

Coder100 (17018)

no no
it's actually a replit bug where the .env file isn't read!!

https://replit.com/bugs @Quackalicious

Quackalicious (0)

oh really? I wasted so much time for dang bug. Well thx anyways or else i probably would have wasted even more time

Quackalicious (0)

Wait but then how did it work for you? the example you showed me worked.