• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

JSON return format ok?

Basically just looking for input or a thumbsup if it looks ok to you.

I'm wanting to create a simple, standardized json format. My app isn't that complicated, and I want to keep things thin, so I'm basically using a 'best of' mashup of various JSON return standards.

Every Json request will return a standard set of variables along with any specific data that was requested. I know this adds some extra, sometimes unneccesary payload to each request, but I want to keep things consistent.



resource = url
function = name of service
status = error/success
message = message body for error codes or other generic info
data = specific function data
IP = ip of client
date = timestamp of request



Code:
  <!--- example return JSON --->

{
  "resource": "https://my.com/users.cfc",
  "function": "functionName",
  "status": "success",
  "message": "",
  "data": "123123",
  "IP": "98.78.211.33",
  "date": "2015-07-17 06:03:30"
}

Code:
  <!--- example return JSON --->

{
  "resource": "https://my.com/users.cfc",
  "function": "functionName",
  "status": "error",
  "message": "database error",
  "data": "",
  "IP": "98.78.211.33",
  "date": "2015-07-17 06:03:30"
}
 
Last edited:
Mostly unnecessary IMO.

Every time you request something, the client is going to know what resource it requested, what IP it requested, when it requested, the status code of the request, etc. There really isn't much point in adding all that information onto the request coming back when you can get that information even before the request is made (or can add it after the request finishes). (Checkout the mdn on it here https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest).

If you have an http library pulling this information out is pretty simple.

If you really want to include some of this. I would suggest that you consider putting a lot of it into the header instead of the JSON (Though most of it is already in the header). Or rather after receiving the response have the client tack on this extra information.
 
Mostly unnecessary IMO.

Every time you request something, the client is going to know what resource it requested, what IP it requested, when it requested, the status code of the request, etc. There really isn't much point in adding all that information onto the request coming back when you can get that information even before the request is made (or can add it after the request finishes). (Checkout the mdn on it here https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest).

If you have an http library pulling this information out is pretty simple.

If you really want to include some of this. I would suggest that you consider putting a lot of it into the header instead of the JSON (Though most of it is already in the header). Or rather after receiving the response have the client tack on this extra information.

Thanks.

Would this be better? These 3 elements would be critical for most requests I make.


Code:
{
  "status": "",
  "message": "",
  "data": ""
}
 
Thanks.

Would this be better? These 3 elements would be critical for most requests I make.


Code:
{
  "status": "",
  "message": "",
  "data": ""
}

Message and data maybe. However, I don't really see why you need a status item. After all, http provides a ton of status codes that have some pretty good meaning. Everything ok? 200. Things went wrong? 500. Access denied? 401. I'm a teapot? 410

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
 
Back
Top