How to parse such json?

How to parse such json?

imballamaimballama Posts: 12Questions: 5Answers: 0

Good afternoon. Tell me please. How can you parse it?

{
  "data": {
    "5": {
      "2022-01-01": 100,
      "2022-01-02": null,
      "2022-01-03": null,
      "2022-01-04": null,
      "2022-01-05": null,
      "2022-01-06": null,
      "2022-01-07": null,
      "2022-01-08": null,
      "2022-01-09": null,
      "2022-01-10": null,
      "2022-01-11": null,
      "2022-01-12": null,
      "2022-01-13": null,
      "2022-01-14": null,
      "2022-01-15": null,
      "2022-01-16": null,
      "2022-01-17": null,
      "2022-01-18": null,
      "2022-01-19": null,
      "2022-01-20": null,
      "2022-01-21": null,
      "2022-01-22": null,
      "2022-01-23": null,
      "2022-01-24": null,
      "2022-01-25": null,
      "2022-01-26": null,
      "2022-01-27": null,
      "2022-01-28": null,
      "2022-01-29": null,
      "2022-01-30": null,
      "2022-01-31": null,
      "id": 5,
      "initials": " фио",
      "place_of_work": " ППБ"
    },
    "6": {
      "2022-01-01": 250,
      "2022-01-02": null,
      "2022-01-03": null,
      "2022-01-04": null,
      "2022-01-05": null,
      "2022-01-06": null,
      "2022-01-07": null,
      "2022-01-08": null,
      "2022-01-09": null,
      "2022-01-10": null,
      "2022-01-11": null,
      "2022-01-12": null,
      "2022-01-13": null,
      "2022-01-14": null,
      "2022-01-15": null,
      "2022-01-16": null,
      "2022-01-17": null,
      "2022-01-18": null,
      "2022-01-19": null,
      "2022-01-20": null,
      "2022-01-21": null,
      "2022-01-22": null,
      "2022-01-23": null,
      "2022-01-24": null,
      "2022-01-25": null,
      "2022-01-26": null,
      "2022-01-27": null,
      "2022-01-28": null,
      "2022-01-29": null,
      "2022-01-30": null,
      "2022-01-31": null,
      "id": 6,
      "initials": " фио2",
      "place_of_work": " ППБ"
    }
  }
}

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    That's not a format that can be parsed, as all the keys are changing. You would need to use a format with constant keys in each record,

    Colin

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Just to add to that, the data property must be an array. DataTables does not at this time support objects as the main data source for each row. A row itself can use an object, but the per rows aspect must be an array. You would need to transform your data object to an array.

    Allan

  • imballamaimballama Posts: 12Questions: 5Answers: 0

    Then the keys will lose their uniqueness(

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Exactly - the uniqueness is the problem, as DataTables needs to know where to put each field in the table. If they're unique, then they can't be referenced.

    As it's calendar data, you could change the data to be an array, then that would be referencable, as first value goes in the first column, etc.

    Colin

Sign In or Register to comment.