C
C
cyberlain2016-08-27 20:42:37
JavaScript
cyberlain, 2016-08-27 20:42:37

What should be the json containing, for example, such data?

  • Toyota
    • Corolla
      • Generation 1990-97
      • Generation 1999-2002
      • Generation 2001 -2004

    • Rav 4
    • Land cruiser
    • Avensis

  • Volkswagen
  • Ford

I understand that the question is very simple, but still, how would you display this list in json format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2016-08-27
@cyberlain

Not such a trivial task, really.
From the point of view of simplifying the work with this list in code, I would form it like this:

{
  "Toyota": {
    "Corolla": {
      "Поколение 1990-97": null,
      "Поколение 1999-2002": null,
      "Поколение 2001 -2004": null
    },
    "Rav 4": null,
    "Land Cruiser": null,
    "Avensis": null
  },
  "Volkswagen": null,
  "Ford": null
}

As a result, there are only two options: an object or null . Any simple type can be used instead of null : string, true/false, or number, but null seems to me the best option - it indicates that there is no nested object.
Corolla generations, for example, could be represented as an array, but then a third type would be added that would need to be processed. Apparently, this object will need to be traversed recursively, and recursion itself can be confusing, you should not complicate your work with a zoo of branching options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question