3

This is my JSON

{
    "name": "dockerizing-magento",
    "description": "ADockerizedMagentoCommunityEdition",
    "require": {
        "magento-hackathon/magento-composer-installer": "v2.1.1",
        "magento/core": "1.9.1.0-patch1"
    },
    "require-dev": {},
    "repositories": [],
    "extra": {
        "magento-root-dir": "web",
        "auto-append-gitignore": true
    },
    "config": {
        "discard-changes": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-install-cmd": [],
        "post-update-cmd": []
    }
}

When i try to composer update

it gives error of

[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
BOM detected, make sure your input does not include a Unicode Byte-Order-Mark

update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] []...

but it is valid according to several websites

https://jsonformatter.curiousconcept.com/

for example here

I follow this tutorial

https://andykdocs.de/development/Docker/Dockerize-Magento

But for hours, i got this error. Please help

I try to build a magento inside docker.

fff
  • 179
  • 2
  • 2
  • 15

2 Answers2

4

The Byte Order Mark (BOM for short) is something that only exists in a file. When an editor or text viewer renders your composer.json, it removes the BOM, So if you paste the contents of composer.json into a web based linter, it won't have the BOM anymore and so web based tools that you're pasting into, will validate it. What you should do is remove the BOM from the file which you can do with an awk command that I borrowed from this answer

mv composer.json composer-bom.json # rename file with BOM
awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}{print}' composer-bom.json > composer.json
rm -f composer-bom.json # delete file with BOM
Community
  • 1
  • 1
Asaph
  • 159,146
  • 25
  • 197
  • 199
0

I ran into awk not being recognized in my PowerShell. So I found a much simpler solution. Open Notepad and simply copy and past what's in the composer file. Save the file and then rename the file composer.json and everything will work as you had expected it to.