如何为Map< String,Integer>定义JSON模式? [英] How to define JSON Schema for Map<String, Integer>?

查看:173
本文介绍了如何为Map< String,Integer>定义JSON模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个json:

{
"itemType": {"food":22,"electrical":2},
"itemCount":{"NA":211}
}

此处的itemType和itemCount将是公用的,但其中的值(食品,NA,电气)将保持不变,但会不断变化,但格式为:地图

Here the itemType and itemCount will be common but not the values inside them (food, NA, electrical) which will be keep changing but the will be in the format : Map

如何为此类通用结构定义Json Schema?

How do I define Json Schema for such generic structure ?

我尝试过:

"itemCount":{
      "type": "object"
    "additionalProperties": {"string", "integer"}

    }

推荐答案

您可以:

{
  "type": "object",
  "properties": {
    "itemType": {"$ref": "#/definitions/mapInt"},
    "itemCount": {"$ref": "#/definitions/mapInt"}
  },
  "definitions": {
    "mapInt": {
      "type": "object",
      "additionalProperties": {"type": "integer"}
    }
  }
}

这篇关于如何为Map< String,Integer>定义JSON模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆