0

I have a JSON

{
"data": {
    "message": { “success” }
    "user": {
        "id": "1234",
        "playlist": [
            [
                "title",
                "album",
                "artist",
                "info"
            ],
            [
                "title",
                "album",
                "artist",
                "info"
            ]
        ]
    }
}

}

I want to fill MYSQL tables using the same. However i am a novice at python thus not sure how to do the same. How should i make sure that MYSQL tables are auto-updated when the JSON hits the server.

what i have tried is

db.execute("INSERT INTO json_col VALUES %s", title,album,artist,info)
4
  • are you trying to store json data as a whole in your table or update individual tables and fields in your database based on the json values? Commented May 20, 2015 at 11:50
  • 1
    You could use django + django rest famework and add a ModelViewSet to create an interface for this purpose. The benefit will be limited as you only store JSON in a column, without any intelligence. Other databases with JSON support may be more suitable. Commented May 20, 2015 at 11:52
  • Parse the values with python in order to insert the value for the corresponding column key, but you need to specify what value to what column, and your schema needs to match this. Commented May 20, 2015 at 12:45
  • @ Gil i am trying to update individual tables and fields in your database based on the json values. Commented May 21, 2015 at 6:07

1 Answer 1

1

I guess you are trying to insert your playlist values into corresponding fields in a table:

for list in dict['data']['user']['playlist']:
    db.execute("INSERT INTO json_col (title, album, artist, info) VALUES (%s, %s, %s, %s)" % 
        (list[0], list[1], list[2], list[3]))
db.commit()
Sign up to request clarification or add additional context in comments.

2 Comments

@ konart: thats precisely what i am trying to do. add playlist values from json to my tables.
@vedami So... was my answer helpful than?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.