json-style
Original:🇺🇸 English
Translated
This skill should be used when the user asks to "format JSON", "design JSON API", "write JSON response", "structure JSON data", or needs guidance on JSON naming conventions and best practices based on Google's JSON Style Guide.
5installs
Added on
NPX Install
npx skill4agent add the-perfect-developer/the-perfect-opencode json-styleTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →JSON Style Guide
Apply Google's JSON Style Guide conventions for consistent, well-structured JSON APIs and data formats.
Overview
This skill provides guidelines for creating JSON APIs and data structures following Google's JSON Style Guide. The guide clarifies naming conventions, property structures, reserved property names, and standard patterns for JSON requests and responses in both RPC-based and REST-based APIs.
Core Principles
Use Double Quotes
All property names must be surrounded by double quotes. String values must use double quotes. Other value types (boolean, number, null, arrays, objects) should not be quoted.
json
{
"propertyName": "string value",
"count": 42,
"isActive": true,
"data": null
}No Comments
Do not include comments in JSON objects. JSON does not support comments in the specification.
Flatten Data Appropriately
Data should be flattened unless there is a clear semantic reason for structured hierarchy. Group properties only when they represent a single logical structure.
Structured (preferred for related data):
json
{
"company": "Google",
"address": {
"line1": "111 8th Ave",
"city": "New York",
"state": "NY",
"zip": "10011"
}
}Property Naming
Naming Format
Property names must:
- Be meaningful with defined semantics
- Use camelCase (not snake_case or PascalCase)
- Start with a letter, underscore (_), or dollar sign ($)
- Contain only letters, digits, underscores, or dollar signs
- Avoid JavaScript reserved keywords
json
{
"firstName": "John",
"lastName": "Doe",
"accountBalance": 1000.50,
"isVerified": true
}Singular vs Plural
Use plural names for arrays. Use singular names for all other properties.
json
{
"author": "lisa",
"siblings": ["bart", "maggie"],
"totalItems": 10,
"itemCount": 10
}JSON Maps vs Objects
When using a JSON object as a map (associative array), keys can use any Unicode characters. Map keys do not need to follow property naming guidelines.
json
{
"address": {
"addressLine1": "123 Anystreet",
"city": "Anytown"
},
"thumbnails": {
"72": "https://url.to.72px.thumbnail",
"144": "https://url.to.144px.thumbnail"
}
}Property Values
Valid Value Types
Property values must be:
- Boolean: or
truefalse - Number: integers or floating-point
- String: Unicode strings in double quotes
- Object:
{} - Array:
[] - Null:
null
JavaScript expressions and functions are not allowed.
Empty or Null Values
Consider removing properties with empty or null values unless there is a strong semantic reason. A property with value , , or may have semantic meaning and should be kept.
0false""json
{
"volume": 10,
"balance": 0,
"currentlyPlaying": null
}Better:
json
{
"volume": 10,
"balance": 0
}Enum Values
Represent enums as strings (not numbers) to handle graceful changes as APIs evolve.
json
{
"color": "WHITE",
"status": "ACTIVE"
}Standard Data Types
Dates
Format dates according to RFC 3339:
json
{
"lastUpdate": "2007-11-06T16:34:41.000Z",
"createdAt": "2024-02-19T10:30:00.000Z"
}Time Durations
Format durations according to ISO 8601:
json
{
"duration": "P3Y6M4DT12H30M5S"
}Latitude/Longitude
Format coordinates according to ISO 6709 using ±DD.DDDD±DDD.DDDD degrees format:
json
{
"location": "+40.6894-074.0447"
}Standard JSON Structure
Top-Level Properties
A JSON response should have these optional top-level properties:
- - Version of the API (string)
apiVersion - - Client-set value echoed by server (string)
context - - Server-assigned response identifier (string)
id - - Operation performed (string)
method - - Input parameters for RPC requests (object)
params - - Container for successful response data (object)
data - - Error details if request failed (object)
error
A response should contain either or , but not both.
dataerrorjson
{
"apiVersion": "2.1",
"data": {
"kind": "user",
"id": "12345",
"name": "John Doe"
}
}Data Object Properties
Common properties in the object:
data- - Type of object (should be first property)
kind - - Fields present in partial response
fields - - Entity tag for versioning
etag - - Unique identifier
id - - Language code (BCP 47)
lang - - Last update timestamp (RFC 3339)
updated - - Boolean marker for deleted entries
deleted - - Array of items (should be last property)
items
Pagination Properties
For paginated data in the object:
data- - Number of items in current response
currentItemCount - - Requested page size
itemsPerPage - - Index of first item (1-based)
startIndex - - Total available items
totalItems - - Current page number (1-based)
pageIndex - - Total number of pages
totalPages - - URI template for pagination
pagingLinkTemplate
Link Properties
Link properties in the object:
data- /
self- Link to retrieve this resourceselfLink - /
edit- Link to update/delete this resourceeditLink - /
next- Link to next pagenextLink - /
previous- Link to previous pagepreviousLink
Error Object Properties
When an error occurs, use the object:
error- - HTTP status code (integer)
code - - Human-readable error message (string)
message - - Array of error details (array)
errors
Each error in array can have:
errors- - Service identifier
domain - - Error type identifier
reason - - Detailed error message
message - - Where error occurred
location - - How to interpret location
locationType - - URI to help documentation
extendedHelp - - URI to error report form
sendReport
json
{
"apiVersion": "2.0",
"error": {
"code": 404,
"message": "File Not Found",
"errors": [{
"domain": "Calendar",
"reason": "ResourceNotFoundException",
"message": "File Not Found"
}]
}
}Property Ordering
While property order is not enforced by JSON, certain orderings improve parsing efficiency:
- should be first - Helps parsers determine object type early
kind - should be last in
items- Allows reading collection metadata before parsing itemsdata
json
{
"data": {
"kind": "album",
"title": "My Photo Album",
"totalItems": 100,
"items": [
{
"kind": "photo",
"title": "My First Photo"
}
]
}
}Quick Reference
Naming Checklist
- Use camelCase for property names
- Use plural names for arrays
- Use singular names for other properties
- Avoid JavaScript reserved keywords
- Choose meaningful, semantic names
Value Type Checklist
- Use strings for enum values
- Format dates as RFC 3339
- Format durations as ISO 8601
- Remove null/empty values unless semantically meaningful
- Use appropriate types (boolean, number, string, object, array, null)
Structure Checklist
- Include in responses
apiVersion - Use for success,
datafor failures (not both)error - Place first in objects
kind - Place last in
itemsobjectdata - Use reserved property names for standard semantics
Additional Resources
Reference Files
For detailed specifications:
- - Complete naming rules and reserved keywords
references/naming-conventions.md - - Full list of reserved property names and their semantics
references/reserved-properties.md - - Detailed pagination implementation patterns
references/pagination-patterns.md
Example Files
Working examples in :
examples/- - Standard API response structure
examples/api-response.json - - Error handling example
examples/error-response.json - - Pagination example with all properties
examples/paginated-response.json