1

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.

Ian
  • 25
  • 4
  • Does this answer your question? [What is the datatype to store json object into postgresql?](https://stackoverflow.com/questions/52577388/what-is-the-datatype-to-store-json-object-into-postgresql) – Stu Aug 04 '22 at 21:20
  • @Stu Not completely. The unique part (for me) was an array of barX in foo1. In that answer, it doesn't quite address the array part as they're only one key one value in the json object. But not to worry, apparently I accidentally typed the question in the format I needed! Thanks. – Ian Aug 06 '22 at 11:10

1 Answers1

0

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.

Mussie
  • 154
  • 1
  • 7