title: How to validate bower.json?
body: <p>I have an error with my bower.json file.</p>
  
  <p>A google has turned up that this is quite common, often because of a non-printable character (due to using an editor that uses such characters). </p>
  
  <p>Is there a way to validate the file locally from the cli? </p>
  
  <p>As an FYI, my error is as follows:</p>
  
  <pre><code>bower meltingpot#*          EMALFORMED Failed to read /tmp/james/bower/meltingpot-5659-xBMHsL/bower.json
  
  Additional error details:
  Unexpected token ]
  </code></pre>
  
  <p>The contents of my bower.json file are as follows:</p>
  
  <pre><code>{
    "name": "meltingpot",
    "version": "0.0.1",
    "homepage": "https://github.com/jamesjenner/meltingpot",
    "authors": [
      "james-jenner &lt;james.jenner@########.com&gt;"
    ],
    "description": "HTML based application, websockets for comms and node.js for backend",
    "keywords": [
      "application",
      "websocket",
      "node"
    ],
    "license": "MIT",
    "ignore": [
      "**/.*",
      "Gruntfile.js",
      "application.js",
      "bower_components",
      "comms.js",
      "node_modules",
      "*.json",
      "panelHandler.js",
      "shared/panel.js",
      "test",
      "tests"
    ]
  }
  </code></pre>
  
  <p>While I'm happy if someone can point out the cause of the problem, the real question is how do I validate the bower.json file to detect and identify any errors. Preference would be that the line is provided where the error occurs.</p>
  
  <p>:edit:</p>
  
  <p>I created a quick script to read in the bower file, parse the data via JSON and then stringify the result. From experience if the json file contained malformed json then I would have received an exception. So it looks like the problem isn't with the format of the file, but with the contents.</p>
  
  <p>Code I used to test the file:</p>
  
  <pre><code>var fs = require('fs');
  
  var data;
  
  try {
    data = fs.readFileSync('bower.json');
  } catch (e) {
    if (e.code === 'ENOENT') {
      // ENOENT is file not found, that is okay, just means no records
    } else {
      // unknown error, lets throw
      throw e;
    }
  }
  
  var json = JSON.parse(data);
  console.log(JSON.stringify(json, null, ' '));
  </code></pre>
  
  <p>:edit:</p>
  
  <p>I've now tested using the <code>bower-json</code> package (thanks to <a href="https://stackoverflow.com/users/409068/jayeff">jayeff</a>), and still validates as okay. Code used is as follows:</p>
  
  <pre><code>var bowerJson = require('bower-json');
  
  // Can also be used by simply calling bowerJson()
  bowerJson.read('./bower.json', function (err, json) {
      if (err) {
          console.error('There was an error reading the file');
          console.error(err.message);
          return;
      }
  
      console.log('JSON: ', json);
  
      try {
        bowerJson.validate(json);
      } catch (err) {
          console.error('There was an error validating the object');
          console.error(err.message);
      }
  });
  </code></pre>
  
  <p>:edit:</p>
  
  <p>Just to be clear on the solution (provided by <a href="https://stackoverflow.com/users/1097634/drorb">drorb</a> below), the problem was that I had created a tag, noticed the extra comma and then fixed the comma just by committing the change. As far as bower was concerned, it was taking the latest release/tag, so was ignoring the fix in my commit.</p>
  
  <p>In addition, while in git you can remove a version via <code>git -d &lt;tag&gt;</code>, bower appears to take the release, not the latest tag (there are complications with how github uses releases). In my case I deleted 0.1.0, added 0.0.1 and bower register ignored 0.0.1. I was forced to create a 0.1.1 tag (after committing the changes in the bower.json file) and then I was able to register.</p>
  
  <p>I've now discovered that you can delete the releases from github, via the website interface (refer <a href="https://help.github.com/articles/editing-and-deleting-releases/" rel="nofollow noreferrer">Editing and Deleting Releases</a>). I was able to tidy up my releases, update the <code>package.json</code> and then push the release I wanted via <code>git tag &lt;tag&gt; -a -m "&lt;desc&gt;"</code> and <code>git push --tags</code>. Now <code>bower info &lt;mypackage&gt;</code> displays the correct information.</p>
  
  <p>I've added the above, as this was not discussed when I looked through other stackoverflow posts that have this problem. I hope the above makes clear the issue of tags and commits with bower, trying to register and how to tidy up any mistakes.</p>
  
  <p>I also recommend reading <a href="http://bob.yexley.net/creating-and-maintaining-your-own-bower-package/" rel="nofollow noreferrer">Creating and Maintaining your own Bower Package</a>.</p>