how do i insert json value into database

Hi Experts,
 how to insert the below json value into db?
 how to validate is it valid json or not?
 i will get dynamic json values , i mean it is not static it will differ every
 can some suggest me how to do
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what type of database is it?
how to validate is it valid json or not?
With a JSON parser. If it won't parse properly, it's invalid

Use a PreparedStatement to do the insert - it will escape the string correctly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srikoteshAuthor Commented:
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

In that case I would do what @CEHJ said.
srikoteshAuthor Commented:
To validate json object is valid or not below is the program

package com.howtodoinjava.restful;

import org.json.JSONException;
import org.json.JSONObject;

public class ValidJson {

	public static void main(String[] args) {
		String json = " {\"location\":{\"value\":\"\"},\"category\":{\"value\":\"33\"},\"criticality\":{\"value\":\"PROD\"}}";

	private static boolean isValidJSONStringArray(String requestBody) {
		try {
			new JSONObject(requestBody);
		} catch (JSONException jsonEx) {
			return false;
		return true;


Open in new window

srikoteshAuthor Commented:
i have taken my json object as string and inserted in db successfully.
That's good though that method name could be more generic - what happens if no array is involved?
srikoteshAuthor Commented:
sorry, I forgot to change method name like is valid json object
If I gave invalid json it will returns false
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.