Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.

Validate Json

Luke Bakken edited this page Oct 5, 2016 · 1 revision

Validate JSON Pre-Commit Hook

Source File on GitHub

This function can be used in a pre-commit hook to validate that the input is a valid JSON document.

function validateJSON(object){

  // A delete is a type of put in Riak so check and see what this
  // operation is doing and pass over objects being deleted
  if (obj.values[0]['metadata']['X-Riak-Deleted']){
    return obj;
  }

  try {
    Riak.mapValuesJson(object);
    return object;
  } catch(e) {
    return {"fail":"Object is not JSON"};
  }
}

Clone this wiki locally