0

This question already has an answer here:

I'm running below curl command from the command line (Git Bash on Windows) or as part of a Bash Script.

curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "{\"testField\":\"ä\"}" https://someurl...

The body of the curl command has an Umlaut ä.

The server which is a Spring Boot REST API running in an AWS Elastic Beanstalk Container returns the following error:

JSON parse error: Invalid UTF-8 middle byte 0x22; nested exception is com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 middle byte 0x22\n at [Source: (PushbackInputStream); line: 1, column: 17]

The same curl command imported into Postman works just fine, so I believe it's rather a curl issue than a server problem.

marked as duplicate by jayhendren, G-Man, Jesse_b, LinuxSecurityFreak, Kiwy May 3 '18 at 9:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Why not use a Unicode escape? – Ignacio Vazquez-Abrams May 2 '18 at 20:02
  • The inputs come from users either as a copy paste or a text file, so I'd like to avoid having to manually convert any extended ascii characters. – Bernie Lenz May 2 '18 at 20:10
  • 1
    The issue isn't really the accented character; it's that the data encoding does not match the parse encoding. How would your system react if the input were, say, ISO 2022-JP encoded instead of (I assume) Windows code page 1252? Just ignoring text within quotes doesn't cut it, because 0x22 is not always " in ISO 2022-JP. Can you enforce a specific input encoding? If not, can you reliably determine the encoding given? – Fox May 2 '18 at 20:55
2

Try replacing the character ä with its UTF8 encoding \u00e4:

curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"testField":"u00e4"}' https://someurl..
  • The inputs come from users either as a copy paste or via a text file, so I'd like to avoid having to manually convert any extended ascii characters. – Bernie Lenz May 2 '18 at 20:10
  • Then you'll need to use a Unicode encoding library of some kind. There are ones available in most popular languages (Python, PHP), so just choose your favorite... – jayhendren May 2 '18 at 20:18
  • If you want to stick to bash, you can probably use jq. For instance: echo '{"testField":"u00e4"}' | jq . -a yields { "testField": "u00e4" }. – jayhendren May 2 '18 at 20:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.