I want to make a string a JSON

0
# Import(s)

import json

def saveLearned(newKnowledge):
    reply = "hola"
    mind = "'" + "{" + '"' + newKnowledge + '"' + " : " + '"' + reply + '"' + "}" + "'"

    json = mind
    print(json)
    load = json.load(json)
    print(load)
    dump = json.dumps(load)
    print(dump)

with open("../data/learned/" + newKnowledge + ".json", "w+") as f:
    json.dump(dump, f)

I have this code, I know it's wrong but I wanted to make a sketch. I want to make mind (currently a string) is transformed into a dictionary to later dump it into a JSON. I do not know how to do it, I do not know if someone could help me.

newKnoledge is a String

reply is a String

What it does

with open("../data/learned/" + newKnowledge + ".json", "w+") as f: json.dump(dump, f)

is to create a JSON with the name of the String that it obtains at the moment of being invoked.

    
asked by guskikalola 18.11.2018 в 19:13
source

0 answers