Encoding for JSON Arguments
In Dropbox API v2, content-upload and content-download endpoints take their JSON arguments in the Dropbox-API-Arg HTTP header or in the arg URL parameter.
If you’re using an official Dropbox SDK, you do not need to manually encode your parameters; the SDK will do this for you.
If you’re not using an official Dropbox SDK, you should make sure to apply the proper encoding. Some libraries will automatically do this for you.
If you use the arg URL parameter, generate a JSON string, encode it as UTF-8, then use the application/x-www-form-urlencoded rules to encode the value.
If you use the Dropbox-API-Arg header, you need to make it “HTTP header safe”. This means using JSON-style “\uXXXX” escape codes for the character 0x7F and all non-ASCII characters.
We based this determination on the original HTTP/1.1 specification (RFC 2616) and as well as the newer HTTP/1.1 specification (RFC 7230). The former suggests that all you need to escape is 0x7F. The later recommends escaping all non-ASCII characters.
Generating HTTP-header-safe JSON
Here are examples of making HTTP-header-safe JSON in a few different languages. As an example, each of these takes the input:
and produce the properly encoded string:
C# (Json.NET, JsonConvert):
C# (Json.NET, JsonTextWriter):
Java (Jackson):
JavaScript:
Objective-C:
Python:
PHP:
Swift: