You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JSON校验提示重复对象键错误,请求修正示例JSON

修正后的JSON代码

你的JSON出现重复键错误,是因为JSON对象不允许存在重复的键名,解析器会直接忽略重复的键,导致数据丢失或报错。核心问题及修正方案如下:

  • 原recipes数组内的单个对象重复了mr_id和ingredients,需将两个食谱拆分为recipes数组的两个独立元素;
  • 每个ingredients数组内的单个对象重复了食材相关字段,需将每个食材作为ingredients数组的独立对象。

修正后的JSON代码:

{
    "recipes": [
        {
            "mr_id": 1,
            "ingredients": [
                {
                    "ingredient_id": 2,
                    "quantity": 4,
                    "unit": "g",
                    "nutrients": [
                        {
                            "nutrient_id": 1,
                            "quantity": 2,
                            "unit": "g"
                        }
                    ]
                },
                {
                    "ingredient_id": 3,
                    "quantity": 4,
                    "unit": "g",
                    "nutrients": [
                        {
                            "nutrient_id": 2,
                            "quantity": 2,
                            "unit": "g"
                        }
                    ]
                }
            ]
        },
        {
            "mr_id": 2,
            "ingredients": [
                {
                    "ingredient_id": 4,
                    "quantity": 4,
                    "unit": "g",
                    "nutrients": [
                        {
                            "nutrient_id": 3,
                            "quantity": 2,
                            "unit": "g"
                        }
                    ]
                },
                {
                    "ingredient_id": 5,
                    "quantity": 4,
                    "unit": "g",
                    "nutrients": [
                        {
                            "nutrient_id": 4,
                            "quantity": 2,
                            "unit": "g"
                        }
                    ]
                }
            ]
        }
    ]
}

内容的提问来源于stack exchange,提问作者user3408779

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 22:35:27