How to convert nested JSON object into a MySQL table?

Viewed 20

I want to convert the following JSON file into a table in MySQL database.

{       "name": "JORGE SEBASTIAN ANGULO",
        "WINS": "0",
        "LOSSES": "0",
        "DRAWS": "0",
        "KO %": "0%",
        "ROUND KO PERCENTAGE": "0%",
        "ROUNDS BOXED": "0",
        "BEEN STOPPED": "0",
        "OPPONENTS STOPPED": "0",
        "BEEN KO'D PERCENTAGE": "0%",
        "BEEN KO'D ROUND PERCENTAGE": "0%",
        "AVERAGE WINNING ROUND": "0",
        "AVERAGE LOSING ROUND": "0",
        "KNOCKOUT %": "0%",
        "EST. POWER": "0%",
        "EST. CHIN/BODY": "0%",
        "win_type": {},
        "opponent": {
            "TOTAL FIGHT COUNT": "0",
            "EST. POWER AVERAGE": "0%",
            "EST. PUNCH RESISTANCE": "0%"
        }
}

I'm using the 'Table Data Import Wizard' on MySQL WorkBench to import the file. I've set "opponent" and "win_type" field as json, and everything else as text.

And I'm getting the following error :

Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'D PERCENTAGE,BEEN KO'D ROUND PERCENTAGE,AVERAGE WINNING ROUND,AVERAGE LOSI' at line 1

I am just getting acclimated with SQL, and not sure what the problem is. Any advices on why this import isn't working would be apprecieated.

1 Answers

Percentage is a reserved character. Probably mySQL workbench is not escaping it properly. Try changing the file and escaping it replacing % by \%

Related