0

How to insert data from JSON file to mysql using node js.

For example :

{
    "root": {
        "child": [
            { "textNode": "First & Child" },
            { "textNode": "Second Child" }
        ],
        "testAttrs": {
            "_attr1": "attr1Value"
        }
    }
}
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Maki
  • 1
  • 1
  • 5
  • It's a JSON object. Just make it into a variable, like so: `var obj = {…your JSON…}` and access it like so: `obj.root.child[0].textNode`, then put each accessed value into the SQL statement. If you're in doubt, `require('fs')` and use `JSON.parse()` on the file. – Kebman Mar 17 '17 at 09:08
  • 1
    Possible duplicate of [How to parse JSON using Node.js?](http://stackoverflow.com/questions/5726729/how-to-parse-json-using-node-js) – Georg Grab Mar 17 '17 at 09:48
  • Your question is extremely general. Do you want to know: Q1 …how to get the data from the JSON-file and into the application? Q2: …how to know how to parse the JSON-data? Q3: …how to access values in the parsed JSON-object? Q4: …how to implement a Node.js driver plugin for MySQL and use it? Qn: All of the above? – Kebman Mar 17 '17 at 11:09

0 Answers0