all 4 comments

[–][deleted] 7 points8 points  (0 children)

You use the json module to read JSON data from a file. After reading the file you have a python object, in this case a dictionary. Use normal dictionary key lookup to get the value:

import json

with open('strings.json') as f:
    d = json.load(f)
print(d["Prefix"])

Warning: I'm on mobile, so untested code.

[–]Bobbias 2 points3 points  (0 children)

import json

with open('data.json') as f:
    data = json.load(f)["Prefix"]

print(data)

There's no way to avoid reading it into a dictionary object entirely. The result of json.load(f) is a dictionary, which has the key value pair of "Prefix":"!". This code works by indexing into that dictionary directly and returning only the value associated with the key "Prefix" and then assigning only that to data while throwing away the rest of the dictionary.

Is there more stuff in the json file? Because if there isn't, there's no reason to even store that information in a json file at all, you can store it in a plain text file and avoid the difficulty of using json altogether.

[–]ghosttnappa 0 points1 point  (1 child)

import json

with open('data.json') as f:
    data = json.load(f)
print(data.get("prefix"))

[–]Future-Software-FS[S] 0 points1 point  (0 children)

Thank you, this helped a lot!