How to use jsonlint - 10 common examples

To help you get started, we’ve selected a few jsonlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jsonresume / resume-cli / lib / pre-flow / get-resume.js View on Github external
fs.readFile(jsonLocation, function(resumeJsonDoesNotExist, data) {

    if (resumeJsonDoesNotExist) {
      if (['export', 'test'].indexOf(process.argv[2]) !== -1) { // removed serve. test this later
        console.log('There is no resume.json file located in this directory');
        console.log('Type: `resume init` to initialize a new resume');
        return;
      }

      var resumeJson = false;
      callback(null);
    } else {
      try {
        jsonlint.parse(String(data));
        var resumeJson = JSON.parse(data);

        callback(null, resumeJson);
      } catch (error) {
        callback(error);
      }
    }
  });
}
github jsonresume / resume-cli / lib / pre.js View on Github external
fs.readFile('./resume.json', function(resumeJsonDoesNotExist, data) {

      if (resumeJsonDoesNotExist) {
        if (['export', 'publish', 'test'].indexOf(process.argv[2]) !== -1) { // removed serve. test this later
          console.log('There is no resume.json file located in this directory');
          console.log('Type: `resume init` to initialize a new resume');
        }

        var resumeJson = false;
        callback(null);
      } else {
        try {
          jsonlint.parse(String(data));
          var resumeJson = JSON.parse(data);

          callback(null, resumeJson);
        } catch (error) {
          callback(error);
        }
      }
    });
  },
github uber / xviz / modules / schema / src / file-validation.js View on Github external
export function parseJSONFile(filePath) {
  const contents = fs.readFileSync(filePath, 'utf8');

  let data;
  try {
    data = JSON.parse(contents);
  } catch (e) {
    try {
      jsonlintParse(contents);
    } catch (egood) {
      // Ugly hack to get the line number out of the jsonlint error
      const lineRegex = /line ([0-9]+)/g;
      const results = lineRegex.exec(egood.message);
      let line = 0;
      if (results !== null) {
        line = parseInt(results[1], 10);
      }

      // Return the best error we can
      throw new ParseError(`${filePath}:${line}: ${egood}`);
    }
  }

  return data;
}
github chrisuehlinger / Flathead / public / src / components / RouteEditor.jsx View on Github external
_validateResponseText(jsonString) {

    try {
      JSON.parse(jsonString);
      return {
        valid: true,
        error: ''
      };
    }
    catch (ex) {
      try {
        jsonlint.parse(jsonString);
        return {
          valid: true,
          error: ''
        };
      } catch (ex) {

        // retrieve line number from error
        let lineMatch = ex.message.match(/line ([0-9]*)/);
        if (lineMatch && lineMatch.length > 1) {
          //Highlight error line.
          this.highlightErrorLine(+lineMatch[1] - 1);
        }
        return {
          valid: false,
          error: ex.message.toString()
        };
github derbyparty / generator-derby / test / common.js View on Github external
fs.readFile(file, {encoding: 'utf-8'}, function(err, src){
      var errors;
      try{
        jsonlint(src);
      }catch(err){
        errors = err.message;
      }
      done(null, errors ? [file, errors] : null);
    });
  },
github divshot / divshot-cli / lib / cwd.js View on Github external
function validateConfigFile (fileContents) {
  try {
    jsonlint.parse(fileContents);
  }
  catch (e) {
    var msgArr = e.message.split('\n');
    var msg = msgArr[1] + '\n' + msgArr[2];
    
    feedback.info();
    feedback.error('Invalid Divshot configuration file. ' + msgArr[0] + '\n');
    feedback.info(msg);
    
    process.exit(1);
  }
}
github katat / vbot / src / index.js View on Github external
return new Promise(async (resolve, reject) => {
      let playbook;
      try {
        let json = fs.readFileSync(filePath).toString('utf-8')
        playbook = jsonlint.parse(json);
      } catch (ex) {
        return reject(ex)
      }
      resolve(playbook);
    })
  }
github katat / vbot / src / index.js View on Github external
return new Promise(async (resolve, reject) => {
      let playbook;
      try {
        let json = fs.readFileSync(filePath).toString('utf-8')
        playbook = jsonlint.parse(json);
      } catch (ex) {
        return reject(ex)
      }
      resolve(playbook);
    })
  }
github tmpfs / rlx / lib / util / lint.js View on Github external
function json(data, cb) {
  var jsonlint = require('jsonlint');
  var result;
  try{
    result = jsonlint.parse(data);
  }catch(e) {
    return cb(e);
  }
  cb(null, result);
}
github appcelerator / alloy / Alloy / utils.js View on Github external
function parseManifestAsCollection(wFile) {
		var wDir = path.dirname(wFile);
		var manifest;
		try {
			manifest = jsonlint.parse(fs.readFileSync(wFile, 'utf8'));
		} catch (e) {
			exports.die('Error parsing "' + wFile + '"', e);
		}

		return {
			dir: wDir,
			manifest: manifest
		};
	}

jsonlint

Validate JSON

Unknown
Latest version published 7 years ago

Package Health Score

44 / 100
Full package analysis

Popular jsonlint functions