Seldaek / jsonlint

JSON Lint for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can/should JSON be checked for duplicate keys?

simensen opened this issue · comments

Take the following example:

{
    "name": "dflydev/repository-testing",
    "authors": [
        {
            "name": "Beau Simensen",
            "email": "beau@dflydev.com"
        }
    ],
    "require": {
        "php": ">=5.3.2"
    },
    "repositories": [
        {

            "type": "vcs",
            "url": "http://github.com/composer/composer",

            "type": "vcs",
            "url": "http://github.com/composer/packagist"

        }
    ]
}

The above passes composer validate but will not work as expected and is not "correct." Is this something the linter can check for? Does it actually make sense to do so?

This is based on a #composer discussion relating to this composer.json snippet:

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "doctrine/migrations",
                "version": "1.0",
                "dist": {
                    "url": "https://github.com/user/migrations.git",
                    "type": "zip"
                }
            },
            "type": "package",
            "package": {
                "name": "doctrine/dbal",
                "version": "1.0",
                "dist": {
                    "url": "https://github.com/user/dbal.git",
                    "type": "zip"
                }
            }
        }
    ]
}

I didn't see the mistake right away. Once I did, I was going to suggest having run composer validate to detect these types of problems except that I discovered composer validate didn't actually throw any errors in this case.

I think it should because it does not make sense to duplicate a key (it is not strictly broken but only the second one will be used)

Strictly speaking it is valid json, that's the problem, but if possible it would be nice to add it I agree.

BTW you can do a repo of type package and then: `"package": [ { ... }, { ... } ]" to have many packages without the visual overhead of many repos.