Johannes N
Johannes N

Reputation: 263

Parse complex JSON in Typescript

The response of a request delivers a JSON. The structure of the JSON looks like this:

{
"32": {
    "docKey": "32",
    "outletId": 32,
    "mdngOutlet": {
        "outletBasic": {
            "outletId": 32,
        }
    }
},
"33": {
    "docKey": "32",
    "outletId": 32,
    "mdngOutlet": {
        "outletBasic": {
            "outletId": 32,
        }
    }
},
"34": {
    "docKey": "32",
    "outletId": 32,
    "mdngOutlet": {
        "outletBasic": {
            "outletId": 32,
        }
    }
},
"35": {
    "docKey": "32",
    "outletId": 32,
    "mdngOutlet": {
        "outletBasic": {
            "outletId": 32,
        }
    }
},
}

What does the interface look like? 32, 33, 34, ... seem to act like map. How can you use a map in an interface?

Upvotes: 0

Views: 71

Answers (1)

Haijin
Haijin

Reputation: 2681

Typescript interface can have dynamic keys.

interface YourJSON{
    [key: string]: yourObjectInterface
}

Upvotes: 1

Related Questions