Jump to content
NotionCommotion

Storing data in a JSON text column

Recommended Posts

I am building a Highcharts configuration tool where the resultant options object is stored as JSON in a text database column (I will not be supporting functions in the options object, so JSON will work).

 

I will have a page which will display various properties of a given chart such as the type of chart, its title, the legend names, etc.

 

I am thinking of not storing any of the properties in a separate column of the table, but just using json_decode() to get the values.

 

"If" I need to create a list of all Pie charts, Bar charts, etc, I will store the chart type as a separate column and duplicate the data.

 

Any concerns?  Thanks

{
    "chart": {
        "plotBackgroundColor": null,
        "plotBorderWidth": null,
        "plotShadow": false,
        "type": "pie"
    },
    "title": {
        "text": "Browser market shares January, 2015 to May, 2015"
    },
    "tooltip": {
        "pointFormat": "{series.name}: <b>{point.percentage:.1f}%</b>"
    },
    "plotOptions": {
        "pie": {
            "allowPointSelect": true,
            "cursor": "pointer",
            "dataLabels": {
                "enabled": true,
                "format": "<b>{point.name}</b>: {point.percentage:.1f} %",
                "style": {
                    "color": "black"
                }
            }
        }
    },
    "series": [
        {
            "name": "Brands",
            "colorByPoint": true,
            "data": [
                {
                    "name": "Microsoft Internet Explorer",
                    "y": 56.33
                },
                {
                    "name": "Chrome",
                    "y": 24.03,
                    "sliced": true,
                    "selected": true
                },
                {
                    "name": "Firefox",
                    "y": 10.38
                },
                {
                    "name": "Safari",
                    "y": 4.77
                },
                {
                    "name": "Opera",
                    "y": 0.91
                },
                {
                    "name": "Proprietary or Undetectable",
                    "y": 0.2
                }
            ]
        }
    ]
}
Edited by NotionCommotion

Share this post


Link to post
Share on other sites

If you are absolutely, positively, 100% sure you will not ever need to actually do any queries to return data sets based off stuff within there, then it shouldn't be an issue

Share this post


Link to post
Share on other sites

If you are absolutely, positively, 100% sure you will not ever need to actually do any queries to return data sets based off stuff within there, then it shouldn't be an issue

 

Thanks Josh,

 

Not today, but maybe one day, and if so, I will parse the text and duplicate the appropriate data in its own column.

 

I didn't originally say so, but the data (i.e. {"name": "Microsoft Internet Explorer","y": 56.33}) will not be stored in the file as it comes from a different source.  Instead of hard coding a value of 56.33, maybe it will store the primary key of a record?  But then if that record got deleted, I wouldn't have any foreign key constraint.  Instead, maybe I should exclude this data from the JSON and store it in a database?  Or maybe keep it both places; the JSON for the legend name and order (and any other Highchart features which are only display oriented), and the database for foreign key constraints only?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.