csharp-sparkpost icon indicating copy to clipboard operation
csharp-sparkpost copied to clipboard

Odd JSON encoding

Open yepher opened this issue 9 years ago • 3 comments

While working with a user here I received an example JSON output from him. He is running: <package id="SparkPost" version="1.2.0" targetFramework="net46" />

This is the JSON I received:

{
    "Id": null,
    "State": null,
    "Options": {
        "StartTime": null,
        "OpenTracking": true,
        "ClickTracking": true,
        "Transactional": true,
        "Sandbox": null,
        "SkipSuppression": null,
        "InlineCss": null,
        "IpPool": null
    },
    "Recipients": [{
        "Address": {
            "Name": "First lash",
            "Email": "[email protected]",
            "HeaderTo": null
        },
        "ReturnPath": null,
        "Tags": ["AbcDef",
        "blah1",
        "en",
        "False"],
        "Metadata": {

        },
        "SubstitutionData": {

        },
        "Type": 0
    }],
    "ListId": null,
    "CampaignId": "ResetPassword - Development",
    "Description": null,
    "Metadata": {

    },
    "SubstitutionData": {
        "dynamic_html": {
            "content": "\u003c!-- Add so the MTA knows this is an HTML email --\u003e\r\n\r\n\r\n\r\nHi John,\u003cbr /\u003e\u003cbr /\u003e\r\nYou recently requested a link to reset your Ukraine Brides Agency password.\u003cbr/\u003e\u003cbr/\u003e\r\nPlease set a new password by following the link below:\u003cbr/\u003e\u003cbr/\u003e\r\n\u003ca href=\"https://localhost/account/changeresetpassword?userId=2\"\u003eClick to reset your password\u003c/a\u003e\u003cbr/\u003e\u003cbr/\u003e\r\nIf you did not request this link then please simply ignore this email.\u003cbr/\u003e\u003cbr/\u003e\r\nPlease feel free to contact our \u003ca href=\"mailto:[email protected]\"\u003e24/7 support team\u003c/a\u003e if you need any assistance.\u003cbr/\u003e\u003cbr/\u003e\r\n\r\nThank you\u003cbr/\u003e\u003cbr/\u003e\r\n\r\nUkraine Brides Agency\u003cbr/\u003e\r\nFriendships - Relationships - Marriage"
        },
        "subject": "Password reset",
        "can_include_unsubscribe_message": false,
        "email_settings_link": "#"
    },
    "ReturnPath": null,
    "Content": {
        "Html": null,
        "Text": null,
        "Subject": null,
        "From": {
            "Name": "Some Name",
            "Email": "[email protected]",
            "HeaderTo": null
        },
        "ReplyTo": null,
        "Headers": {

        },
        "Attachments": [],
        "InlineImages": [],
        "TemplateId": "notification",
        "UseDraftTemplate": null
    },
    "TotalRecipients": 0,
    "NumGenerated": 0,
    "NumFailedGeneration": 0,
    "NumInvalidRecipients": 0
}

This output threw me for a moment because several fields are not part of the transmission post. For example:

"TotalRecipients": 0,
"NumGenerated": 0,
"NumFailedGeneration": 0,
"NumInvalidRecipients": 0

I am also not used to seeing non-set field in the serialized JSON. It is common to not transmit empty fields. For example this is in the JSON:

"ReturnPath": null,

I don't think this will cause any processing error but it does take a moment to get used to.

One last bit of formatting that was a bit surprising (maybe this should be a separate issue) is all the Unicode in the content like \u003c. The JSON should be serialized as UTF-8 instead of Unicode.

yepher avatar Apr 26 '16 14:04 yepher

One last bit of formatting that was a bit surprising (maybe this should be a separate issue) is all the Unicode in the content like \u003c. The JSON should be serialized as UTF-8 instead of Unicode.

I think it's a common issue https://github.com/SparkPost/python-sparkpost/issues/114

spoof avatar May 11 '16 11:05 spoof

Thank you @spoof, that helps greatly!

I think in our case I have to control the encoding elsewhere. I don't think it's a result of the json lib but of the web call. But I'm still investigating. Your note gave me an idea for a good test case.

darrencauthon avatar May 11 '16 14:05 darrencauthon

I am sending mail using template, without any bug mail is going but the recipient is not receiving an mail.

ganeshgholap1984 avatar May 04 '17 04:05 ganeshgholap1984