Skip to content

Instantly share code, notes, and snippets.

@am11
Created July 20, 2014 07:09
Show Gist options
  • Save am11/589f526ac45960e20f5e to your computer and use it in GitHub Desktop.
Save am11/589f526ac45960e20f5e to your computer and use it in GitHub Desktop.
JSON to CSON conversion
fs.readFile(params.sourceFileName, 'utf8', function (err, data) {
if(data)
data = JSON.parse(data);
if (err || !data) {
err = err || "Invalid JSON content found";
writer.write(JSON.stringify({
Success: false,
SourceFileName: params.sourceFileName,
TargetFileName: params.targetFileName,
Remarks: "CSON: Error reading input file.",
Details: err,
Errors: [{
Message: "CSON: " + err,
FileName: params.sourceFileName
}]
}));
writer.end();
return;
}
writer.write(JSON.stringify({
Success: true,
SourceFileName: params.sourceFileName,
TargetFileName: params.targetFileName,
Remarks: "Successful!",
Content: CSON.stringifySync(data);
}));
writer.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment