简体   繁体   中英

How do I organize Nested JSON Objects Data in a SQL Database?

I have a JSON file with some data, like this:

{
    "meta":{
        "server":"awesome.com",
        "user":"awesomeUser",
        "response":"200"
    },
    "data":{
        "tags":["campaign","awesome"],
        "parameters":[{"$ref":"#/components/parameters/campaign"}],
        "responses":{
            "campaign":{
                "name":"My first awesome campaign",
                "description":"This is an amazing campaign",
                "content":{
                    "id":"000001",
                    "publisher":"awesome",
                    "active":true,
                    "launched":354658465,
                    "users":{
                        "countries":{
                            "USA":"753365"
                        }
                    }
                }
            },
            "publisher":{
                "name":"awesome",
                "id":"000099",
                "authorized":true,
                "defaultCurrency":"USD"
            }
        }
    }
}

I need to build a database with this data, but I'm not sure how to organize the tables, specially the nested objects. For example, I know one table could be "meta", that would have the server, user and response columns. then the data table that has the tags, parameters and responses rows, but those are an array, an array of objects and an objetc that has more objects in it.

How do I manage that in the database?

I'm trying this from scratch because I'm learning, is there a way of making it a little more easier?

Please kindly let me know if I explained myself correctly and thank you so much in advance.

It's understandable that you are confused about the best way to store your JSON data.

The way to organize nested JSON documents is more or less equivalent to organizing denormalized relational tables.

You have to start with the queries you need to run. That determines the best way to organize the data. You store the data in a form that is most convenient for the lookups you will need to do.

If you don't know what queries will be needed, or if you have a variety of different types of queries, then the best strategy is to organize data by rules of normalization , and store them in multiple tables. Ie do not use JSON at all, use normal rows and columns. This at least reduces redundancy and makes the data support the broadest variety of different queries in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM