Unfortunately, JSON only allows strings as key names (cf. Using number as "index" (JSON)), the provided example should then be like this:
{
"10": {
"12000": 10000000,
"14000": 23432423,
},
"20": {
"35000": 6747665,
"45000": 54635454
}
}
And in OpenAPI (fka. Swagger) specification, you can define maps but the type of the key is implicit and is supposed to be string (just like with JSON).
When describing an object which is a <string, something>
map, you have to use additionalProperties
to describe something
.
Here are two ways of describing a schema corresponding to a <string, <string, integer>>
map:
swagger: '2.0'
info:
version: 1.0.0
title: Maps
paths: {}
definitions:
# a <string, <string, integer>> map using
# inline definition of <string, integer> map item
TwoDimensionMap:
additionalProperties:
additionalProperties:
type: integer
format: int64
# a <string, integer> map
SimpleMap:
additionalProperties:
type: integer
format: int64
# a <string, <string, integer>> map using
# $ref definition of <string, integer> map item
TwoDimensionMapWithRef:
additionalProperties:
$ref: '#/definitions/SimpleMap'
TwoDimensionMap
is a full inline definition and TwoDimensionMapWithRef
describe exactly the same thing but using a reference to another definition for the inner <string, integer>
map.