Created
July 20, 2014 07:09
-
-
Save am11/589f526ac45960e20f5e to your computer and use it in GitHub Desktop.
JSON to CSON conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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