1

I am generating json from email in Outlook using VBA.

The content of Meetingitem.Body includes newlines. When I include this content in my json as a string, I get an error.

Is it possible to avoid this?

{"fields": {
    "project": {
        "id": 30611
    },
    "summary": "Release Produktion-System",
    "description": "Guten Tag

Sie erhalten diese Terminanfrage weil Ihnen im Change 2018.04.24.015 <http://pww.post.ch/appl/oe/it/changemanagement/wpl/pages/editchange.aspx?changeId=29774>  die im Betreff aufgeführte Tätigkeit zugeordnet wurde. Bitte bestätigen Sie die Terminanfrage im Outlook, damit für die Ausführung der Tätigkeit der entsprechende Zeitraum in Ihrem Kalender reserviert wird.
(Unter offene Termine die entsprechende Tätigkeit mit Bearbeiten öffnen, und den Status anpassen. Es stehen Ihnen folgende Abschlussstatus zur Verfügung: Erledigt, Verzögert, Abgebrochen).

Freundliche Grüsse
Muster Mus

Musterfirma
Informatik

Telefon: +553344556622
Email: muster.muss@mail.com

",
    "issuetype": {
        "name": "Test"
    }
}
}

It is a POST request to server and here is the response:

{
    "errorMessages": [
        "Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value\n at [Source: org.apache@4jasdn4; line: 6, column: 28]"
    ]
}

To generate this json I am using following code (short variant):

Dim smry, descrp, jsTest As String
smry = """summary"""
descrp = """description"""
jsTest = "{" + smry + ":" + """" + CStr(Msg.Subject) + """" + "," + descrp + ":" + """" + CStr(Msg.Body) + """" + "}"
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
khashashin
  • 1,058
  • 14
  • 40
  • 1
    Replace `CStr(Msg.Body)` with `Replace(Replace(Replace(CStr(Msg.Body), vbLf, "\n"), vbCr, "\r"), vbTab, "\t")` – omegastripes Jun 12 '18 at 18:21
  • 1
    Duplicate of [How do I handle newlines in JSON?](https://stackoverflow.com/questions/42068/how-do-i-handle-newlines-in-json): "The reason for having to do this: [RFC 4627 - JSON spec](http://www.ietf.org/rfc/rfc4627.txt) - *All Unicode characters may be placed within the quotation marks except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F). Since a newline is a control character, it must be escaped.*" – paulsm4 Nov 16 '18 at 18:58

0 Answers0