1

Can someone riddle me this please...

An instance of the following Envelope class with the email property set to "This is line1\nThis is line 2". Essentially the emailBlurb property contains a carriage returned captured by the client application.

public class Envelope
{
    public string emailBlurb;
}

When serialized to json the net result is..

{
   "emailBlurb": "This is line1\\nThis is line 2".  
}

Json dictates that special characters will be transported using an escaping backslash. So far everything seems fine except when I create the envelope with message ends of literally being:

This is line1\nThis is line 2

If I modify the json after serialization to replace "\\n" with "\n" DocuSign accepts the carriage return as desired and the message format suits the user...

This is line 1
This is line 2

While I suppose where needed I can 'correct' the results of the json serializer this seems like a hack. Is this a bug on DocuSign's service receiving end?

JSON.net is the serializer in question if that's of interest.

Mike
  • 780
  • 1
  • 5
  • 26

1 Answers1

1

You don't need to escape in the blurb, see below result and example:

Test for basic docx a 
   line break in the blurb

Sample:

--AAA
Content-Type: application/json
Content-Disposition: form-data

{
    "emailBlurb": "Test for basic docx a 
    line break in the blurb",
    "emailSubject": "Test for docx with
    a line break in the subject",
    "status": "sent",
    "compositeTemplates": [
        {
            "inlineTemplates": [
                {

                    "sequence": "1",
                    "documents": [
                        {
                            "documentId": "1",
                            "name": "basic.docx"
                        }
                    ],
                    "recipients": {
                        "signers": [
                            {
                                "recipientId": "1",
                                "name": "David W Grigsby",
                                "email": "youremail@yourdomain.com",
                                "defaultRecipient": "true",
                                "tabs": {
                                    "signHereTabs": [{
                                    "anchorString": "\\Signhere\\",
                                    "tabLabel": "Sign Here 1"
                                    }]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    ]
}

--AAA
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: file; filename="basic.docx"; documentid=1
Content-Transfer-Encoding: base64

UEsD
David W Grigsby
  • 1,554
  • 1
  • 13
  • 23
  • You've hardcoded a line break into your json. This is not representative how line breaks are stored in .net classes which is \n. The spec dictates that all special characters are to be escaped which is why serializers (in my case JSON.net) are escaping the \n to \\n when the classes serialize up. Question still remains why does \n work when \\n does not. At this point i'm doing a string.Replace(@"\\n", @"\n") which works fine but seems unnecessary. emailBlurb is the only place I can see where this is relevant with DocuSign but in other systems allowing formatting this would be a problem. – Mike Jan 07 '15 at 05:12
  • 1
    Mike, I believe (not looking at the internal code) but this is legacy behavior from SOAP and Salesforce type connectors that need this behavior, so your and my "work around" is viable, but not ideal. Please feel free to reach out to DocuSign support to file a bug and let's see what the official word is, but I suspect that this is such an ingrained behavior it may be not be resolvable without breaking many others. I agree with your line of "Json spec", but like you, live in what let's us get work done. – David W Grigsby Jan 07 '15 at 18:08