JSON API ordering of values

I’m just starting to write my iOS app, but am having problems creating the JSON. Testing my JSON output in the sandbox I get output like this (some data obfuscated)
{
“payload” : {
“Body” : {
“SearchParameters” : {
“OrderResultsBy” : “CompanyName”,
“ReturnCount” : “10”,
“Offset” : “0”,
“OrderDirection” : “ASC”
}
},
“Header” : {
“MessageType” : “Request”,
“SubmissionNumber” : “20170424091750”,
“Authentication” : {
“ApplicationID” : “*****",
“AccNumber” : "",
“MD5Value” : "

}
}
}
}

When I paste this into the sandbox I get errors from your API because the JSON is in the wrong order. However, the JSON spec says that JSON objects are expected to be unordered, and should be able to be parsed in any order. (And iOS offers no easy way to force the JSON output to be in order, short of writing my own JSON serialiser rather than using the built-in one)

Is it possible to get your API updated to allow this?

Thanks.

In the first version of the API, we built the JSON interface as a proxy on top of the XML API. As the XML API is bound by XSD schemas it will enforce strict ordering of elements.

We will look at this in future releases to see if it is possible to relax the ordering.

EDIT:

I have had a chat with an engineer and there may be a way for us to modify the schemas to allow the elements to be presented in any order. This is something we’ll be looking into shortly.

That’d be great, thanks!

Hello TellyTart

The issue here is as much the construction of the JSON string/file as it is the API.

What language are you developing in? I’m using Python which has the same ‘feature’ of unordered objects, lists, etc. It is necessary to use functions like OrderedDict or to build the JSON string manually to ensure the correct order.

Many uses of JSON requires a structured format . While the order of elements within a section should not be critical to an API, keeping the sub-sections within the top section is fundamental to referencing items in a tree like fashion.

This allows one function for creating the ‘payload’ section, which is used by all calls, and separate functions to create the ‘body’ for each query required.

Rgds Ian

I’m developing in Swift 3.0 for iOS using xCode. It has no concept of ordered dictionaries, and the JSON spec itself doesn’t expect items to be ordered in any particular way.

I’ll wait to see what the QF devs come up with, as I’m loath to have to write my own JSON constructor functions for every API call I’ll need to make!

This topic was automatically closed after 7 days. New replies are no longer allowed.