JSON Array to MySql Insert Query

Rishabh jaishwal
2 min readMay 30, 2019

--

Today, I wish to let you know a small trick to create a MySql query from JSON Array. Developers who is working on core language without using framework they generally face problem to insert a large data into databases which is present in the JSON Array format.

Here, I am depicting a way through which you can make your work easy. As for the example I am going to take a JSON Array of Country and Currency which is required to be stored in MySql database.

Raw JSON Array for Country

Now, We are going to create a function which take 3 parameter in my case. First parameter is for Table name , Second Parameter for Column Name and Third parameter for JSON Array .

Function for Converting JSON Array into a MySql Insert Query String

Now, Call this function to get a String which is used to Insert Data into MySql Database.

Calling Function JsonToQuery

And In last you will get a String which is used as MySql Query

Output of function JsonToQuery

It’s just an basic idea to create a dynamic MySql query using this Small and Easy function. The above piece of code is written into JavaScript. You can code this logic into any language according to your need.

--

--