0

I have this git log command:

  const command = [
    `git log ${branch} -${count} --grep="${grep}"`,
    ` --pretty=format:'{"subject":"%s","body":"%b","commit":"%h","sanitized_subject_line":"%f",`,
    `"commit_notes":"%N","author":"%aN","date":"%aD"}'`
  ];

it's getting JSON from the git log. The problem I have is that I think there are some newline characters in the body (%b) that's preventing the JSON from being parsed correctly.

So I need to do something like this:

git log --pretty=format:'{"subject":"%s"}' | remove_bad_chars

how can I replace any newline characters that the git log command outputs? (or any characters that might break JSON parsing).

  • Newlines shouldn't break json parsing, probably something else. – jordanm Mar 27 '18 at 17:29
  • @jordanm that might be true, is there some way to sanitize json using a pipe? to ready the json for propa parsin? – Alexander Mills Mar 27 '18 at 17:33
  • @jordanm I think unescaped newlines might cause a problem? – Alexander Mills Mar 27 '18 at 17:36
  • 1
    Perhaps you should include an example of the bad json that fails to parse. – jordanm Mar 27 '18 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.