Home > Software engineering >  JSON Validation Showing as Duplicate Object warnings
JSON Validation Showing as Duplicate Object warnings

Time:11-09

I am new to Json, but I tried below json request.

{
    "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"
            }]

        }]

    }]
}

But when i place this in POSTMAN I am getting duplicate Object keys error , Even i checked in online jsonvalidator websites. Showing same duplicate warnings. Can some one please correct this?

CodePudding user response:

Your json is not valid. Objects in your json are not properly separated, it causes double object property name error. Each object (outer and nested) should be included into brackets {}. This way each mr_id and each ingridient_id would be in the different objects, now they are in the same one.

{
    "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"
                    }]
                }
            ]
        }
    ]
}
  •  Tags:  
  • json
  • Related