How can I store this object in an SQL database?

I’m new to the game and am wondering if it’s possible to store the following object in one column in an SQL database like postgres:

    {
      "foo1": ["bar1", "bar2"],
      "foo2": ["bar1", "bar2", "bar3"],
      "foo3": ["bar1", "bar2"]
    } 

    // Idea is to store a list of values in each foo.

I’m sure I have the syntax incorrect, too; any help is appreciated. Thanks.

>Solution :

Actually, you can use a JSON object.

Example: If you are using Postgres, it started supporting JSON objects since version 9.2 you can use JSON or JSONB as specified
https://www.postgresql.org/docs/current/datatype-json.html

MySQL, Oracle, T-SQL, SQL server … supports it. You can find definitive guide on their documentation.

Leave a Reply