0

The aim is to save user entered JSON into a database. Now, before someone jumps at me, I know json, I know mysql and I know all the links inbetween.

The issue is: I need to safely store the ENTIRE JSON feed in a single cell in the table.

The background: this function will be a temp fix for a tool, that is needed asap but will require a lot of time. The temp fix will allow the system to go live with minimal code.

Users will create a GOOGLE maps style here ( http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html)

and have the JSON made for them

[ { "stylers": [ { "visibility": "off" } ] },{ "featureType": "water", "stylers": [ { "visibility": "on" } ] },{ "featureType": "transit.line", "elementType": "geometry.fill", "stylers": [ { "visibility": "on" }, { "hue": "#ff3300" }, { "color": "#ff0000" }, { "weight": 0.7 } ] },{ "featureType": "transit.station.rail", "stylers": [ { "visibility": "on" }, { "color": "#0000ff" }, { "weight": 4.6 } ] },{ } ] 

The site will then just call the JSON and apply it using jQuery later on. What would my ''best practice'' method be at doing this.

2 Answers 2

1

To answer your specific question, I would agree with the poster 'tom' that you should use a TEXT column.

However, I think for ease of use, you should also use prepared statements. If you create a prepared insert statement, you can then pass in the JSON directly. This will be the best representation in your database of the exact JSON (no annoying slashes) - AND be the safest. Please don't forget to do this step - its very important!

Sign up to request clarification or add additional context in comments.

Comments

0

Since MySQL doesn't have a dedicated JSON column type, I would just store the JSON in an unbounded TEXT column. Just make sure you always check for valid JSON on write.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.