B
B
beduin012015-09-22 22:16:56
JSON
beduin01, 2015-09-22 22:16:56

Did I choose the right JSON structure?

Actually a question. Which JSON option is better/correct.easier to bypass.

{
  "date": 2012-05-14,
  "tags": {
    "Python": 1,
    "Java": 3,
    "Linux": 8
  },
  "status": 0
}

{
  "date": "2012-05-14",
  "tags": [
{"Python": 1},
{"Java": 3},
{"Linux": 8}
  ],
 
  "status": 0
}

In the second case, how do I understand the array of tags, and in the first case they are like subobjects?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Novikov, 2015-09-22
@beduin01

It all depends on the destination. In the first one, the tags object is guaranteed to contain one language (key) each. This can be said to be safer, but if you need several such keys (languages), then the 2nd option is better. However, the 2nd option will be more difficult to process (if you need to know the selected key (language)). This is how it will be better (for the 2nd option):

{
  "date": "2012-05-14",
  "tags": [
    {"id": "Python", "value": 1},
    {"id": "Java", "value": 3},
    {"id": "Linux", "value": 8}
  ],
  "status": 0
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question