我有一个CGI Webhook终点,对我来说只是mails the $POST。
我现在想要打印JSON,以便我可以轻松阅读电子邮件:
payload=%7B%22ref%22%3A%22refs%2Fheads%2Fmaster%22%2C%22after%22%3A%2255deef96327f0625b5f1f724636a84ded63540c3%22%2C%22before%22%3A%22c87b66be0d2bcc93be6de0f0c4ac248642d5abf5%22%2C%22created%22%3Afalse%2C%22deleted%22%3Afalse%2C%22forced%22%3Afalse%2C%22compare%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%2Fcompare%2Fc87b66be0d2b...55deef96327f%22%2C%22commits%22%3A%5B%7B%22id%22%3A%2255deef96327f0625b5f1f724636a84ded63540c3%22%2C%22distinct%22%3Atrue%2C%22message%22%3A%22Harmonising+directory+structure+for+punch%22%2C%22timestamp%22%3A%222013-11-25T23%3A27%3A01-08%3A00%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%2Fcommit%2F55deef96327f0625b5f1f724636a84ded63540c3%22%2C%22author%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22committer%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22added%22%3A%5B%22contents%2Fcalendar%2F_index%2Fmain.markdown%22%2C%22contents%2Fconnect%2F_index%2Fmain.markdown%22%2C%22contents%2Fmembership%2F_index%2FMembershipAgreement.pdf%22%2C%22contents%2Fmembership%2F_index%2Fmain.markdown%22%5D%2C%22removed%22%3A%5B%22contents%2F_calendar%2Fmain.markdown%22%2C%22contents%2F_connect%2Fmain.markdown%22%2C%22contents%2F_membership%2FMembershipAgreement.pdf%22%2C%22contents%2F_membership%2Fmain.markdown%22%5D%2C%22modified%22%3A%5B%5D%7D%5D%2C%22head_commit%22%3A%7B%22id%22%3A%2255deef96327f0625b5f1f724636a84ded63540c3%22%2C%22distinct%22%3Atrue%2C%22message%22%3A%22Harmonising+directory+structure+for+punch%22%2C%22timestamp%22%3A%222013-11-25T23%3A27%3A01-08%3A00%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%2Fcommit%2F55deef96327f0625b5f1f724636a84ded63540c3%22%2C%22author%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22committer%22%3A%7B%22name%22%3A%22Kai+Hendry%22%2C%22email%22%3A%22hendry%40webconverger.com%22%2C%22username%22%3A%22kaihendry%22%7D%2C%22added%22%3A%5B%22contents%2Fcalendar%2F_index%2Fmain.markdown%22%2C%22contents%2Fconnect%2F_index%2Fmain.markdown%22%2C%22contents%2Fmembership%2F_index%2FMembershipAgreement.pdf%22%2C%22contents%2Fmembership%2F_index%2Fmain.markdown%22%5D%2C%22removed%22%3A%5B%22contents%2F_calendar%2Fmain.markdown%22%2C%22contents%2F_connect%2Fmain.markdown%22%2C%22contents%2F_membership%2FMembershipAgreement.pdf%22%2C%22contents%2F_membership%2Fmain.markdown%22%5D%2C%22modified%22%3A%5B%5D%7D%2C%22repository%22%3A%7B%22id%22%3A14509629%2C%22name%22%3A%22hackerspace.sg%22%2C%22url%22%3A%22https%3A%2F%2Fgithub.com%2Fhackerspacesg%2Fhackerspace.sg%22%2C%22description%22%3A%22Hackerspace.sg+2.0+using+Punch%22%2C%22homepage%22%3A%22http%3A%2F%2Fhsg.dabase.com%2F%22%2C%22watchers%22%3A1%2C%22stargazers%22%3A1%2C%22forks%22%3A0%2C%22fork%22%3Afalse%2C%22size%22%3A264%2C%22owner%22%3A%7B%22name%22%3A%22hackerspacesg%22%2C%22email%22%3Anull%7D%2C%22private%22%3Afalse%2C%22open_issues%22%3A0%2C%22has_issues%22%3Atrue%2C%22has_downloads%22%3Atrue%2C%22has_wiki%22%3Afalse%2C%22language%22%3A%22CSS%22%2C%22created_at%22%3A1384821217%2C%22pushed_at%22%3A1385450838%2C%22master_branch%22%3A%22master%22%2C%22organization%22%3A%22hackerspacesg%22%7D%2C%22pusher%22%3A%7B%22name%22%3A%22kaihendry%22%2C%22email%22%3A%22hendry%40iki.fi%22%7D%7D
通过命令行管道。
这个工作有没有好的node.js工具?我猜我需要urldecode并通过JSON漂亮的打印机运行“有效载荷”。如果答案是一行,奖励积分。 ;)
答案 0 :(得分:0)
这个怎么样?
var payload = "your_big_string";
console.log(JSON.stringify(JSON.parse(decodeURIComponent(payload)), null, 4));
如果您想使用process.stdin
作为输入,accum
module可以帮助您将流转换为缓冲区(使用npm i accum
安装):
var accum = require('accum');
process.stdin.pipe(accum(function (data) {
console.log(JSON.stringify(JSON.parse(decodeURIComponent(data.toString())), null, 4));
}));
答案 1 :(得分:0)
查看项目https://github.com/nlf/node-github-hook
当项目页面显示时,
This is a very simple, easy to use evented web hook for github.