I stumbled upon this question while developing my own project, and the answers here are fantastic. Like many of you, I was looking for a simple, pragmatic standard for API responses but couldn't find one that perfectly fit the bill for rapid prototyping while still being scalable.
The closest I found was JSend, but I always felt that checking for success with if (response.status === "success") was slightly less ergonomic than a simple boolean check like if (response.success).
Inspired by the original question and the excellent ideas shared by everyone in this thread, decided to formalize the concepts discussed here into a clear specification.
The goal was to create a specification that 1) It's incredibly simple to start with, 2) Uses a boolean success flag for easy checks, and 3) Provides a clear path for handling more complex scenarios like validation errors and pagination without being overly verbose.
I've put the full specification, its motivation, and the thought process behind it on GitHub. I wanted to share it here for anyone else who is looking for a middle ground between ultra-minimal formats and complex ones like JSON:API.
You can find the full doc on Github: JSO Specification. I welcome any feedback, ideas, or contributions from the community. Thanks!
Here’s a quick look at the basic structure:
Successful Response:
{
"success": true,
"data": {
"id": 1,
"name": "John Doe"
}
}
Simple Failed Response:
{
"success": false,
"message": "The requested resource could not be found."
}
Detailed Failed Response (for validation):
{
"success": false,
"message": "Invalid input provided. Please check the details.",
"errors": [
{
"code": 101,
"message": "Email is invalid.",
"source": { "field": "email" }
}
]
}
P.S. Talk about procrastination since I couldn't continue on development without a proper specification. Haha!