mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Grammatical updates to JSON-C Style Guide. New CSS for HTML version of JSON-C Style Guide.
This commit is contained in:
parent
233b48fc74
commit
8643ca8da7
102
jsoncstyleguide.css
Normal file
102
jsoncstyleguide.css
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
body {
|
||||||
|
background-color: #FFF;
|
||||||
|
color: #666;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 10pt;
|
||||||
|
margin-right: 100px;
|
||||||
|
margin-left: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1, h2, h3, h4, h5, h6, .toc_title {
|
||||||
|
color: #06C;
|
||||||
|
margin-top: 2em;
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, .toc_title {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 12pt;
|
||||||
|
margin-left: -40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3, h4, h5, h6 {
|
||||||
|
font-size: 10pt;
|
||||||
|
margin-left: -20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc_category, .toc_stylepoint {
|
||||||
|
font-size: 10pt;
|
||||||
|
padding-top: .3em;
|
||||||
|
padding-bottom: .3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border-top: 1px solid #CCC;
|
||||||
|
border-bottom: 1px solid #CCC;
|
||||||
|
border-left: 5px solid #CCC;
|
||||||
|
border-right: 5px solid #CCC;
|
||||||
|
padding-left: 12px;
|
||||||
|
padding-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
code,samp,var {
|
||||||
|
color: #060;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
font-size: 10pt;
|
||||||
|
display: block;
|
||||||
|
color: #060;
|
||||||
|
background-color: #F8FFF8;
|
||||||
|
border-color: #F0FFF0;
|
||||||
|
border-style: solid;
|
||||||
|
border-top-width: 1px;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-left-width: 5px;
|
||||||
|
padding-left: 12px;
|
||||||
|
padding-right: 12px;
|
||||||
|
padding-top: 4px;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.badcode {
|
||||||
|
color: #C00;
|
||||||
|
background-color: #FFF8F8;
|
||||||
|
border-color: #FFF0F0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.showhide_button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link_button {
|
||||||
|
background-color: #F8F8FF;
|
||||||
|
border-color: #F0F0FF;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 1px;
|
||||||
|
font-size: 75%;
|
||||||
|
margin-top: 20px;
|
||||||
|
margin-left: -50px;
|
||||||
|
padding: 4px;
|
||||||
|
line-height: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
address {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
margin-top: 10em;
|
||||||
|
border-width: 1px;
|
||||||
|
color: #FFF;
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
<TITLE>Google JSON Style Guide</TITLE>
|
<TITLE>Google JSON Style Guide</TITLE>
|
||||||
<META content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<META content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||||
<LINK rel="shortcut icon" type="image/x-icon" HREF="http://www.google.com/favicon.ico">
|
<LINK rel="shortcut icon" type="image/x-icon" HREF="http://www.google.com/favicon.ico">
|
||||||
<LINK rel="stylesheet" type="text/css" HREF="styleguide.css">
|
<LINK rel="stylesheet" type="text/css" HREF="jsoncstyleguide.css">
|
||||||
<SCRIPT type="text/javascript" language="javascript">
|
<SCRIPT type="text/javascript" language="javascript">
|
||||||
|
|
||||||
function ShowHideByName(bodyName, buttonName) {
|
function ShowHideByName(bodyName, buttonName) {
|
||||||
|
@ -307,7 +307,7 @@ This style guide contains many details that are initially hidden from view. The
|
||||||
<ul>
|
<ul>
|
||||||
<li>property - a name/value pair inside a JSON object.</li>
|
<li>property - a name/value pair inside a JSON object.</li>
|
||||||
<li>property name - the name (or key) portion of the property.</li>
|
<li>property name - the name (or key) portion of the property.</li>
|
||||||
<li>property value - the value portion of the property:</li>
|
<li>property value - the value portion of the property.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -374,7 +374,7 @@ Use double quotes.
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>If a property requires quotes, double quotes must be used. All property names must be surrounded by double quotes. Property values of type string must be surrounded by double quotes. Other value types (like boolean or number) do not need double quotes</p>
|
<p>If a property requires quotes, double quotes must be used. All property names must be surrounded by double quotes. Property values of type string must be surrounded by double quotes. Other value types (like boolean or number) should not be surrounded by double quotes.</p>
|
||||||
|
|
||||||
</DIV>
|
</DIV>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
@ -388,7 +388,7 @@ Use double quotes.
|
||||||
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Flattened_data_vs_Structured_Hierarchy__body','Flattened_data_vs_Structured_Hierarchy__button')" name="Flattened_data_vs_Structured_Hierarchy__button" id="Flattened_data_vs_Structured_Hierarchy__button">▶</SPAN>
|
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Flattened_data_vs_Structured_Hierarchy__body','Flattened_data_vs_Structured_Hierarchy__button')" name="Flattened_data_vs_Structured_Hierarchy__button" id="Flattened_data_vs_Structured_Hierarchy__button">▶</SPAN>
|
||||||
|
|
||||||
<DIV style="display:inline;" class="">
|
<DIV style="display:inline;" class="">
|
||||||
Data should not be arbitrarily grouped for convenience
|
Data should not be arbitrarily grouped for convenience.
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -464,7 +464,7 @@ Choose meaningful property names.
|
||||||
<li>Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.</li>
|
<li>Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.</li>
|
||||||
<li>Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).</li>
|
<li>Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>These guidelines mirror the guidelines for naming JavaScript identifiers. This allows JavaScript clients to access properties using dot notation (for example, result.thisIsAnInstanceVariable). Here's an example of an object with one property:</p>
|
<p>These guidelines mirror the guidelines for naming JavaScript identifiers. This allows JavaScript clients to access properties using dot notation. (for example, <code>result.thisIsAnInstanceVariable</code>). Here's an example of an object with one property:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
|
@ -494,8 +494,8 @@ JSON maps can use any Unicode character in key names.
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The property name naming rules do not apply when a JSON object is used as a map. A map (also referred to as associative arrays) is a data type with arbitrary key/value pairs that use the keys to access the corresponding values. JSON objects and JSON maps look the same at runtime; this distinction is relevant to the design of the API. The API documentation should indicate when JSON objects are used as maps.</p>
|
<p>The property name naming rules do not apply when a JSON object is used as a map. A map (also referred to as an associative array) is a data type with arbitrary key/value pairs that use the keys to access the corresponding values. JSON objects and JSON maps look the same at runtime; this distinction is relevant to the design of the API. The API documentation should indicate when JSON objects are used as maps.</p>
|
||||||
<p>The keys of a map do not have to obey the naming guidelines for property names. Map keys may contain any Unicode characters. Clients can access these properties using the square bracket notation familiar for maps (for example, result.thumbnails["72"]).</p>
|
<p>The keys of a map do not have to obey the naming guidelines for property names. Map keys may contain any Unicode characters. Clients can access these properties using the square bracket notation familiar for maps (for example, <code>result.thumbnails["72"]</code>).</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
|
@ -561,8 +561,8 @@ Array types should have plural property names. All other property names should
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Arrays usually contain multiple items, and a plural property name reflects this. An example of this can be seen in the reserved names below. The "items" property name is plural because it represents an array of item objects. Most of the other fields are singular.</p>
|
<p>Arrays usually contain multiple items, and a plural property name reflects this. An example of this can be seen in the reserved names below. The <code>items</code> property name is plural because it represents an array of item objects. Most of the other fields are singular.</p>
|
||||||
<p>There may be exceptions to this, especially when referring to numeric property values. For example, in the reserved names, "totalItems" makes more sense than "totalItem". However, technically, this is not violating the style guide, since "totalItems" can be viewed as "totalOfItems", where "total" is singular (as per the style guide), and "OfItems" serves to qualify the total. The field name could also be changed to "itemCount" to look singular.</p>
|
<p>There may be exceptions to this, especially when referring to numeric property values. For example, in the reserved names, <code>totalItems</code> makes more sense than <code>totalItem</code>. However, technically, this is not violating the style guide, since <code>totalItems</code> can be viewed as <code>totalOfItems</code>, where <code>total</code> is singular (as per the style guide), and <code>OfItems</code> serves to qualify the total. The field name could also be changed to <code>itemCount</code> to look singular.</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
|
@ -590,7 +590,7 @@ Array types should have plural property names. All other property names should
|
||||||
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Naming_Conflicts__body','Naming_Conflicts__button')" name="Naming_Conflicts__button" id="Naming_Conflicts__button">▶</SPAN>
|
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Naming_Conflicts__body','Naming_Conflicts__button')" name="Naming_Conflicts__button" id="Naming_Conflicts__button">▶</SPAN>
|
||||||
|
|
||||||
<DIV style="display:inline;" class="">
|
<DIV style="display:inline;" class="">
|
||||||
Avoid naming conflicts by choosing a new property name, or versioning the API.
|
Avoid naming conflicts by choosing a new property name or versioning the API.
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -612,7 +612,7 @@ Avoid naming conflicts by choosing a new property name, or versioning the API.
|
||||||
</PRE>
|
</PRE>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<p>If in the future we wish to make "ingredients" a reserved word, we can do one of two things:</p>
|
<p>If in the future we wish to make <code>ingredients</code> a reserved word, we can do one of two things:</p>
|
||||||
<p>1) Choose a different name:</p>
|
<p>1) Choose a different name:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -658,7 +658,7 @@ Avoid naming conflicts by choosing a new property name, or versioning the API.
|
||||||
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Property_Value_Format__body','Property_Value_Format__button')" name="Property_Value_Format__button" id="Property_Value_Format__button">▶</SPAN>
|
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Property_Value_Format__body','Property_Value_Format__button')" name="Property_Value_Format__button" id="Property_Value_Format__button">▶</SPAN>
|
||||||
|
|
||||||
<DIV style="display:inline;" class="">
|
<DIV style="display:inline;" class="">
|
||||||
Property values must be Unicode booleans, numbers, strings, objects, arrays, and <code>null</code>.
|
Property values must be Unicode booleans, numbers, strings, objects, arrays, or <code>null</code>.
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -677,7 +677,7 @@ Property values must be Unicode booleans, numbers, strings, objects, arrays, and
|
||||||
"answerToLife": 42, // number
|
"answerToLife": 42, // number
|
||||||
"name": "Bart", // string
|
"name": "Bart", // string
|
||||||
"moreData": {}, // object
|
"moreData": {}, // object
|
||||||
"anArray": [] // array
|
"things": [] // array
|
||||||
}
|
}
|
||||||
</PRE>
|
</PRE>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
@ -704,7 +704,7 @@ Property values must be Unicode booleans, numbers, strings, objects, arrays, and
|
||||||
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Empty/Null_Property_Values__body','Empty/Null_Property_Values__button')" name="Empty/Null_Property_Values__button" id="Empty/Null_Property_Values__button">▶</SPAN>
|
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('Empty/Null_Property_Values__body','Empty/Null_Property_Values__button')" name="Empty/Null_Property_Values__button" id="Empty/Null_Property_Values__button">▶</SPAN>
|
||||||
|
|
||||||
<DIV style="display:inline;" class="">
|
<DIV style="display:inline;" class="">
|
||||||
If a property is optional or has an empty/null value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.
|
Consider removing empty or <code>null</code> values.
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -713,15 +713,17 @@ If a property is optional or has an empty/null value, consider dropping the prop
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>If a property is optional or has an empty/null value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.</p>
|
<p>If a property is optional or has an empty or <code>null</code> value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
"volume": 10,
|
"volume": 10,
|
||||||
|
|
||||||
// Even though the "balance" property's value is zero, it should be left in,
|
// Even though the "balance" property's value is zero, it should be left in,
|
||||||
// since "0" signifies "even balance" (the value could be "-1" for left
|
// since "0" signifies "even balance" (the value could be "-1" for left
|
||||||
// balance and "+1" for right balance.
|
// balance and "+1" for right balance.
|
||||||
"balance": 0,
|
"balance": 0,
|
||||||
|
|
||||||
// The "currentlyPlaying" property can be left out since it is null.
|
// The "currentlyPlaying" property can be left out since it is null.
|
||||||
// "currentlyPlaying": null
|
// "currentlyPlaying": null
|
||||||
}
|
}
|
||||||
|
@ -763,7 +765,7 @@ Enum values should be represented as strings.
|
||||||
</PRE>
|
</PRE>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<p>JSON Object:</p>
|
<p>JSON object:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
|
@ -883,7 +885,7 @@ Latitudes/Longitudes should be formatted as recommended by ISO 6709.
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H2 name="JSON_Structure_&_Reserved_Property_Names" id="JSON_Structure_&_Reserved_Property_Names">JSON Structure & Reserved Property Names</H2>
|
<H2 name="JSON_Structure_&_Reserved_Property_Names" id="JSON_Structure_&_Reserved_Property_Names">JSON Structure & Reserved Property Names</H2>
|
||||||
|
|
||||||
<p>In order to maintain a consistent interface across APIs, JSON objects should follow the structure outlined below. This structure applies to both requests and responses made with JSON. Within this structure, there are certain property names that are reserved for specific uses. These properties are NOT required; in other words, each reserved property may appear zero or one time. But if a service needs these properties, this naming convention is recommend. Here is a schema of the JSON structure, represented in <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Forderly-json.org%2F">Orderly</a> format (which in turn can be compiled into a <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Fjson-schema.org%2F">JSONSchema</a>). You can few examples of the JSON structure at the end of this guide.</p>
|
<p>In order to maintain a consistent interface across APIs, JSON objects should follow the structure outlined below. This structure applies to both requests and responses made with JSON. Within this structure, there are certain property names that are reserved for specific uses. These properties are NOT required; in other words, each reserved property may appear zero or one times. But if a service needs these properties, this naming convention is recommend. Here is a schema of the JSON structure, represented in <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Forderly-json.org%2F">Orderly</a> format (which in turn can be compiled into a <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Fjson-schema.org%2F">JSONSchema</a>). You can few examples of the JSON structure at the end of this guide.</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>object {
|
<PRE>object {
|
||||||
|
@ -965,7 +967,7 @@ Property Value Type: string<br>Parent: -
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Represents the desired version of the service API in a request, and the version of the service API that's served in the response. "apiVersion" should always be present. This is not related to the version of the data. Versioning of data should be handled through some other mechanism such as etags.</p>
|
<p>Represents the desired version of the service API in a request, and the version of the service API that's served in the response. <code>apiVersion</code> should always be present. This is not related to the version of the data. Versioning of data should be handled through some other mechanism such as etags.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -994,7 +996,7 @@ Property Value Type: string<br>Parent: -
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Client sets this value and server echos data in the response. This is useful in JSON-P and batch situations , where the user can use the "context" to correlate responses with requests. This property is a top-level property because the "context" should present regardless of whether the response was successful or an error. "Context" differs from "id" in that "context" is specified by the user while "id" is assigned by the service.</p>
|
<p>Client sets this value and server echos data in the response. This is useful in JSON-P and batch situations , where the user can use the <code>context</code> to correlate responses with requests. This property is a top-level property because the <code>context</code> should present regardless of whether the response was successful or an error. <code>context</code> differs from <code>id</code> in that <code>context</code> is specified by the user while <code>id</code> is assigned by the service.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
<p>Request #1:</p>
|
<p>Request #1:</p>
|
||||||
|
|
||||||
|
@ -1034,7 +1036,7 @@ Property Value Type: string<br>Parent: -
|
||||||
</PRE>
|
</PRE>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<p>Common JavaScript handler code to process both response:</p>
|
<p>Common JavaScript handler code to process both responses:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>function handleResponse(response) {
|
<PRE>function handleResponse(response) {
|
||||||
|
@ -1097,8 +1099,8 @@ Property Value Type: string<br>Parent: -
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Represents the operation to perform, or that was performed, on the data. In the case of a JSON request, the "method" property can be used to indicate which operation to perform on the data. In the case of a JSON response, the "method" property can indicate the operation performed on the data.</p>
|
<p>Represents the operation to perform, or that was performed, on the data. In the case of a JSON request, the <code>method</code> property can be used to indicate which operation to perform on the data. In the case of a JSON response, the <code>method</code> property can indicate the operation performed on the data.</p>
|
||||||
<p>One example of this is in JSON-RPC requests, where "method" indicates the operation to perform on the "params" property:</p>
|
<p>One example of this is in JSON-RPC requests, where <code>method</code> indicates the operation to perform on the <code>params</code> property:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
|
@ -1132,7 +1134,7 @@ Property Value Type: object<br>Parent: -
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>This object serves as a map of input parameters to send to an RPC request. It can be used in conjunction with the "method" property to execute an RPC function. If an RPC function does not need parameters, this property can be omitted.</p>
|
<p>This object serves as a map of input parameters to send to an RPC request. It can be used in conjunction with the <code>method</code> property to execute an RPC function. If an RPC function does not need parameters, this property can be omitted.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1167,7 +1169,7 @@ Property Value Type: object<br>Parent: -
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Container for all the data from a response. This property itself has many reserved property names, which are described below. Services are free to add their own data to this object. A JSON response should contain either a "data" object or an "error" object, but not both. If both "data" and "error" are present, the "error" object takes precedence.</p>
|
<p>Container for all the data from a response. This property itself has many reserved property names, which are described below. Services are free to add their own data to this object. A JSON response should contain either a <code>data</code> object or an <code>error</code> object, but not both. If both <code>data</code> and <code>error</code> are present, the <code>error</code> object takes precedence.</p>
|
||||||
|
|
||||||
</DIV>
|
</DIV>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
@ -1190,7 +1192,7 @@ Property Value Type: object<br>Parent: -
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Indicates that an error has occurred, with details about the error. The error format supports either one or more errors returned from the service. A JSON response should contain either a "data" object or an "error" object, but not both. If both "data" and "error" are present, the "error" object takes precedence.</p>
|
<p>Indicates that an error has occurred, with details about the error. The error format supports either one or more errors returned from the service. A JSON response should contain either a <code>data</code> object or an <code>error</code> object, but not both. If both <code>data</code> and <code>error</code> are present, the <code>error</code> object takes precedence.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1203,7 +1205,7 @@ Property Value Type: object<br>Parent: -
|
||||||
"domain": "Calendar",
|
"domain": "Calendar",
|
||||||
"reason": "ResourceNotFoundException",
|
"reason": "ResourceNotFoundException",
|
||||||
"message": "File Not Found
|
"message": "File Not Found
|
||||||
....}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</PRE>
|
</PRE>
|
||||||
|
@ -1219,7 +1221,7 @@ Property Value Type: object<br>Parent: -
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H2 name="Reserved_Property_Names_in_the_data_object" id="Reserved_Property_Names_in_the_data_object">Reserved Property Names in the data object</H2>
|
<H2 name="Reserved_Property_Names_in_the_data_object" id="Reserved_Property_Names_in_the_data_object">Reserved Property Names in the data object</H2>
|
||||||
|
|
||||||
<p>The "data" property of the JSON object may contain the following properties.</p>
|
<p>The <code>data</code> property of the JSON object may contain the following properties.</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H3>
|
<H3>
|
||||||
|
@ -1238,7 +1240,7 @@ Property Value Type: string<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The "kind" property serves as a guide to what type of information this particular object stores. It can be present at the "data" level, or at the "items" level, or in any object where its helpful to distinguish between various types of objects. If the "kind" object is present, it should be the first property in the object (See the "Property Ordering" section below for more details).</p>
|
<p>The <code>kind</code> property serves as a guide to what type of information this particular object stores. It can be present at the <code>data</code> level, or at the <code>items</code> level, or in any object where its helpful to distinguish between various types of objects. If the <code>kind</code> object is present, it should be the first property in the object (See the "Property Ordering" section below for more details).</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1337,7 +1339,7 @@ Property Value Type: string<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>A globally unique string used to reference the object. The specific details of the "id" property are left up to the service.</p>
|
<p>A globally unique string used to reference the object. The specific details of the <code>id</code> property are left up to the service.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1403,7 +1405,7 @@ Property Value Type: string (formatted as specified in RFC 3339)<br>Parent: <cod
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Indicates the last date/time (RFC 3339) the item was updated, as defined by the service.</p>
|
<p>Indicates the last date/time (<a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a>) the item was updated, as defined by the service.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1469,12 +1471,12 @@ Property Value Type: array<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The property name "items" is reserved to represent an array of items (for example, photos in Picasa, videos in YouTube). This construct is intended to provide a standard location for collections related to the current result. For example, the JSON output could be plugged into a generic pagination system that knows to page on the "items" array. If "items" exists, it should be the last property in the "data" object (See the "Property Ordering" section below for more details).</p>
|
<p>The property name <code>items</code> is reserved to represent an array of items (for example, photos in Picasa, videos in YouTube). This construct is intended to provide a standard location for collections related to the current result. For example, the JSON output could be plugged into a generic pagination system that knows to page on the <code>items</code> array. If <code>items</code> exists, it should be the last property in the <code>data</code> object (See the "Property Ordering" section below for more details).</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>{
|
<PRE>{
|
||||||
"data" {
|
"data": {
|
||||||
"items": [
|
"items": [
|
||||||
{ /* Object #1 */ },
|
{ /* Object #1 */ },
|
||||||
{ /* Object #2 */ },
|
{ /* Object #2 */ },
|
||||||
|
@ -1495,7 +1497,14 @@ Property Value Type: array<br>Parent: <code>data</code>
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H2 name="Reserved_Property_Names_for_Paging" id="Reserved_Property_Names_for_Paging">Reserved Property Names for Paging</H2>
|
<H2 name="Reserved_Property_Names_for_Paging" id="Reserved_Property_Names_for_Paging">Reserved Property Names for Paging</H2>
|
||||||
|
|
||||||
<p>The following properties are located in the "data" object, and are related to paging items. Some of the language and concepts are borrowed from the <a href="TDOD">OpenSearch specification</a>. The paging properties listed below allows users to page based on number of items. However some services may wish to offer page-based paging. For example, rather than jump to item number 200, some services may request page number 20. For these cases, two page-based properties have been added: "pageIndex" and "totalPages". An example of how to use these properties to implement paging can be found at the end of this guide.</p>
|
<p>The following properties are located in the <code>data</code> object, and help page through a list of items. Some of the language and concepts are borrowed from the <a href="http://www.opensearch.org/Home">OpenSearch specification</a>.</p>
|
||||||
|
<p>The paging properties below allow for various styles of paging, including:</p>
|
||||||
|
<ul>
|
||||||
|
<li>Previous/Next paging - Allows user's to move forward and backward through a list, one page at a time. The <code>nextLink</code> and <code>previousLink</code> properties (described in the "Reserved Property Names for Links" section below) are used for this style of paging.</li>
|
||||||
|
<li>Index-based paging - Allows user's to jump directly to a specific item position within a list of items. For example, to load 10 items starting at item 200, the developer may point the user to a url with the query string <code>?startIndex=200</code>.</li>
|
||||||
|
<li>Page-based paging - Allows user's to jump directly to a specific page within the items. This is similar to index-based paging, but saves the developer the extra step of having to calculate the item index for a new page of items. For example, rather than jump to item number 200, the developer could jump to page 20. The urls during page-based paging could use the query string <code>?page=1</code> or <code>?page=20</code>. The <code>pageIndex</code> and <code>totalPages</code> properties are used for this style of paging.</li>
|
||||||
|
</ul>
|
||||||
|
<p>An example of how to use these properties to implement paging can be found at the end of this guide.</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H3>
|
<H3>
|
||||||
|
@ -1514,7 +1523,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The number of items in this result set. Should be equivalent to items.length, and is provided as a convenience property. Say for example a developer requests a set of search items, and asks for 10 items per page. The total set of that search has 14 total items. The first page of items will have 10 items in it, so both "itemsPerPage" and "currentItemCount" will equal "10". The next page of items will have the remaining 4 items; "itemsPerPage" will still be "10", but "currentItemCount" will be "4".</p>
|
<p>The number of items in this result set. Should be equivalent to items.length, and is provided as a convenience property. For example, suppose a developer requests a set of search items, and asks for 10 items per page. The total set of that search has 14 total items. The first page of items will have 10 items in it, so both <code>itemsPerPage</code> and <code>currentItemCount</code> will equal "10". The next page of items will have the remaining 4 items; <code>itemsPerPage</code> will still be "10", but <code>currentItemCount</code> will be "4".</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1550,7 +1559,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The number of items in the result. This is not necessarily the size of the data.items array; if we are viewing the last page of items, the size of data.items may be less than "itemsPerPage". However the size of data.items should not exceed "itemsPerPage".</p>
|
<p>The number of items in the result. This is not necessarily the size of the data.items array; if we are viewing the last page of items, the size of data.items may be less than <code>itemsPerPage</code>. However the size of data.items should not exceed <code>itemsPerPage</code>.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1584,7 +1593,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The index of the first item in data.items. For consistency, "startIndex" should be 1-based. For example, the first item in the first set of items should have a "startIndex" of 1. If the user requests the next set of data, the "startIndex" may be 10.</p>
|
<p>The index of the first item in data.items. For consistency, <code>startIndex</code> should be 1-based. For example, the first item in the first set of items should have a <code>startIndex</code> of 1. If the user requests the next set of data, the <code>startIndex</code> may be 10.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1618,7 +1627,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The total number of items available in this set. For example, if a user has 100 blog posts, the response may only contain 10 items, but the "totalItems" would be 100.</p>
|
<p>The total number of items available in this set. For example, if a user has 100 blog posts, the response may only contain 10 items, but the <code>totalItems</code> would be 100.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1652,7 +1661,7 @@ Property Value Type: string<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>A uri template indicating how users can calculate subsequent paging links. The uri template also has some reserved variable names: {index} representing the item number to load, and {pageIndex}, representing the page number to load.</p>
|
<p>A URI template indicating how users can calculate subsequent paging links. The URI template also has some reserved variable names: <code>{index}</code> representing the item number to load, and <code>{pageIndex}</code>, representing the page number to load.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1686,7 +1695,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The index of the current page of items. For consistency, "pageIndex" should be 1-based. For example, the first page of items has a "pageIndex" of 1. "pageIndex" can also be calculated from the item-based paging properties: "pageIndex" = floor(startIndex / itemsPerPage) + 1.</p>
|
<p>The index of the current page of items. For consistency, <code>pageIndex</code> should be 1-based. For example, the first page of items has a <code>pageIndex</code> of 1. <code>pageIndex</code> can also be calculated from the item-based paging properties: <code>pageIndex = floor(startIndex / itemsPerPage) + 1</code>.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1720,7 +1729,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The total number of pages in the result set. "totalPages" can also be calculated from the item-based paging properties above: "totalPages" = ceiling(totalItems / itemsPerPage).</p>
|
<p>The total number of pages in the result set. <code>totalPages</code> can also be calculated from the item-based paging properties above: <code>totalPages = ceiling(totalItems / itemsPerPage)</code>.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1742,7 +1751,7 @@ Property Value Type: integer<br>Parent: <code>data</code>
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H2 name="Reserved_Property_Names_for_Links" id="Reserved_Property_Names_for_Links">Reserved Property Names for Links</H2>
|
<H2 name="Reserved_Property_Names_for_Links" id="Reserved_Property_Names_for_Links">Reserved Property Names for Links</H2>
|
||||||
|
|
||||||
<p>The following properties are located in the "data" object, and represent references to other resources. There are two forms of link properties: 1) objects, which can contain any sort of reference (such as a JSON-RPC object), and 2) uri strings, which represent uris to resources (and will always be suffixed with "Link").</p>
|
<p>The following properties are located in the <code>data</code> object, and represent references to other resources. There are two forms of link properties: 1) objects, which can contain any sort of reference (such as a JSON-RPC object), and 2) URI strings, which represent URIs to resources (and will always be suffixed with "Link").</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H3>
|
<H3>
|
||||||
|
@ -1761,7 +1770,7 @@ Property Value Type: object / string<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The self link can be used to retrieve the item's data. For example, in a list of a user's Picasa album, each album object in the "items" array could contain a "selfLink" that can be used to retrieve data related to that particular album.</p>
|
<p>The self link can be used to retrieve the item's data. For example, in a list of a user's Picasa album, each album object in the <code>items</code> array could contain a <code>selfLink</code> that can be used to retrieve data related to that particular album.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1831,7 +1840,7 @@ Property Value Type: object / string<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The next link indicates how more data can be retrieved. It points to the location to load the next set of data. It can be used in conjunction with the itemsPerPage, startIndex and totalItems properties in order to page through data.</p>
|
<p>The next link indicates how more data can be retrieved. It points to the location to load the next set of data. It can be used in conjunction with the <code>itemsPerPage</code>, <code>startIndex</code> and <code>totalItems</code> properties in order to page through data.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1866,7 +1875,7 @@ Property Value Type: object / string<br>Parent: <code>data</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>The previous link indicates how more data can be retrieved. It points to the location to load the previous set of data. It can be used in conjunction with the itemsPerPage, startIndex and totalItems properties in order to page through data.</p>
|
<p>The previous link indicates how more data can be retrieved. It points to the location to load the previous set of data. It can be used in conjunction with the <code>itemsPerPage</code>, <code>startIndex</code> and <code>totalItems</code> properties in order to page through data.</p>
|
||||||
<p>Example:</p>
|
<p>Example:</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -1889,7 +1898,7 @@ Property Value Type: object / string<br>Parent: <code>data</code>
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H2 name="Reserved_Property_Names_in_the_error_object" id="Reserved_Property_Names_in_the_error_object">Reserved Property Names in the error object</H2>
|
<H2 name="Reserved_Property_Names_in_the_error_object" id="Reserved_Property_Names_in_the_error_object">Reserved Property Names in the error object</H2>
|
||||||
|
|
||||||
<p>The "error" property of the JSON object may contain the following properties.</p>
|
<p>The <code>error</code> property of the JSON object may contain the following properties.</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<H3>
|
<H3>
|
||||||
|
@ -2253,7 +2262,7 @@ Property Value Type: string<br>Parent: <code>error.errors</code>
|
||||||
link
|
link
|
||||||
</A></SPAN>
|
</A></SPAN>
|
||||||
|
|
||||||
<p>Suppose a parser is responsible for parsing a raw JSON stream into a specific object. The "kind" property guides the parser to instantiate the appropriate object. Therefore it should be the first property in the JSON object. This only applies when objects have a "kind" property (usually found in the "data" and "items" properties).</p>
|
<p>Suppose a parser is responsible for parsing a raw JSON stream into a specific object. The <code>kind</code> property guides the parser to instantiate the appropriate object. Therefore it should be the first property in the JSON object. This only applies when objects have a <code>kind</code> property (usually found in the <code>data</code> and <code>items</code> properties).</p>
|
||||||
|
|
||||||
</DIV>
|
</DIV>
|
||||||
</DIV>
|
</DIV>
|
||||||
|
@ -2268,7 +2277,7 @@ Property Value Type: string<br>Parent: <code>error.errors</code>
|
||||||
|
|
||||||
<DIV style="display:inline;" class="">
|
<DIV style="display:inline;" class="">
|
||||||
|
|
||||||
<code>items</code> should be the last property in the "data" object
|
<code>items</code> should be the last property in the <code>data</code> object
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -2333,7 +2342,7 @@ Property Value Type: string<br>Parent: <code>error.errors</code>
|
||||||
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('YouTube_JSON_API__body','YouTube_JSON_API__button')" name="YouTube_JSON_API__button" id="YouTube_JSON_API__button">▶</SPAN>
|
<SPAN class="showhide_button" onclick="javascript:ShowHideByName('YouTube_JSON_API__body','YouTube_JSON_API__button')" name="YouTube_JSON_API__button" id="YouTube_JSON_API__button">▶</SPAN>
|
||||||
|
|
||||||
<DIV style="display:inline;" class="">
|
<DIV style="display:inline;" class="">
|
||||||
Here's an example of the YouTube JSON API's response object.
|
Here's an example of the YouTube JSON API's response object. You can learn more about YouTube's JSON API here: <a href="http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html">http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html</a>.
|
||||||
</DIV>
|
</DIV>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
|
@ -2495,7 +2504,7 @@ A list of reserved JavaScript words that should be avoided in property names.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<DIV class="">
|
<DIV class="">
|
||||||
<PRE>abstract
|
<PRE class="badcode">abstract
|
||||||
boolean break byte
|
boolean break byte
|
||||||
case catch char class const continue
|
case catch char class const continue
|
||||||
debugger default delete do double
|
debugger default delete do double
|
||||||
|
|
|
@ -24,7 +24,7 @@ This style guide contains many details that are initially hidden from view. The
|
||||||
<p>This style guide documents guidelines and recommendations for building JSON APIs at Google. In general, JSON APIs should follow the spec found at <a href="http://www.json.org">JSON.org</a>. This style guide clarifies and standardizes specific cases so that JSON APIs from Google have a standard look and feel. These guidelines are applicable to JSON requests and responses in both RPC-based and REST-based APIs.</p>
|
<p>This style guide documents guidelines and recommendations for building JSON APIs at Google. In general, JSON APIs should follow the spec found at <a href="http://www.json.org">JSON.org</a>. This style guide clarifies and standardizes specific cases so that JSON APIs from Google have a standard look and feel. These guidelines are applicable to JSON requests and responses in both RPC-based and REST-based APIs.</p>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
<CATEGORY title="Definitions">
|
<CATEGORY title="Definitions">
|
||||||
<p>For the purposes of this style guide, we define the following terms:</p><ul><li><b>property</b> - a name/value pair inside a JSON object.</li><li><b>property name</b> - the name (or key) portion of the property.</li><li><b>property value</b> - the value portion of the property:</li></ul>
|
<p>For the purposes of this style guide, we define the following terms:</p><ul><li><b>property</b> - a name/value pair inside a JSON object.</li><li><b>property name</b> - the name (or key) portion of the property.</li><li><b>property value</b> - the value portion of the property.</li></ul>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
// The name/value pair together is a "property".
|
// The name/value pair together is a "property".
|
||||||
|
@ -57,12 +57,12 @@ No comments in JSON objects.
|
||||||
Use double quotes.
|
Use double quotes.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>If a property requires quotes, double quotes must be used. All property names must be surrounded by double quotes. Property values of type string must be surrounded by double quotes. Other value types (like boolean or number) do not need double quotes</p>
|
<p>If a property requires quotes, double quotes must be used. All property names must be surrounded by double quotes. Property values of type string must be surrounded by double quotes. Other value types (like boolean or number) should not be surrounded by double quotes.</p>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Flattened data vs Structured Hierarchy">
|
<STYLEPOINT title="Flattened data vs Structured Hierarchy">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Data should not be arbitrarily grouped for convenience
|
Data should not be arbitrarily grouped for convenience.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Data elements should be "flattened" in the JSON representation. Data should not be arbitrarily grouped for convenience.</p><p>In some cases, such as a collection of properties that represents a single structure, it may make sense to keep the structured hierarchy. These cases should be carefully considered, and only used if it makes semantic sense. For example, an address could be represented two ways, but the structured way probably makes more sense for developers:</p>
|
<p>Data elements should be "flattened" in the JSON representation. Data should not be arbitrarily grouped for convenience.</p><p>In some cases, such as a collection of properties that represents a single structure, it may make sense to keep the structured hierarchy. These cases should be carefully considered, and only used if it makes semantic sense. For example, an address could be represented two ways, but the structured way probably makes more sense for developers:</p>
|
||||||
|
@ -101,7 +101,7 @@ Data should not be arbitrarily grouped for convenience
|
||||||
Choose meaningful property names.
|
Choose meaningful property names.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Property names must conform to the following guidelines:</p><ul><li>Property names should be meaningful names with defined semantics.</li><li>Property names must be camel-cased, ascii strings.</li><li>The first character must be a letter, an underscore (_) or a dollar sign ($).</li><li>Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.</li><li>Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).</li></ul><p>These guidelines mirror the guidelines for naming JavaScript identifiers. This allows JavaScript clients to access properties using dot notation (for example, result.thisIsAnInstanceVariable). Here's an example of an object with one property:</p>
|
<p>Property names must conform to the following guidelines:</p><ul><li>Property names should be meaningful names with defined semantics.</li><li>Property names must be camel-cased, ascii strings.</li><li>The first character must be a letter, an underscore (_) or a dollar sign ($).</li><li>Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.</li><li>Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).</li></ul><p>These guidelines mirror the guidelines for naming JavaScript identifiers. This allows JavaScript clients to access properties using dot notation. (for example, <code>result.thisIsAnInstanceVariable</code>). Here's an example of an object with one property:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"thisPropertyIsAnIdentifier": "identifier value"
|
"thisPropertyIsAnIdentifier": "identifier value"
|
||||||
|
@ -115,7 +115,7 @@ Choose meaningful property names.
|
||||||
JSON maps can use any Unicode character in key names.
|
JSON maps can use any Unicode character in key names.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The property name naming rules do not apply when a JSON object is used as a map. A map (also referred to as associative arrays) is a data type with arbitrary key/value pairs that use the keys to access the corresponding values. JSON objects and JSON maps look the same at runtime; this distinction is relevant to the design of the API. The API documentation should indicate when JSON objects are used as maps.</p><p>The keys of a map do not have to obey the naming guidelines for property names. Map keys may contain any Unicode characters. Clients can access these properties using the square bracket notation familiar for maps (for example, result.thumbnails["72"]).</p>
|
<p>The property name naming rules do not apply when a JSON object is used as a map. A map (also referred to as an associative array) is a data type with arbitrary key/value pairs that use the keys to access the corresponding values. JSON objects and JSON maps look the same at runtime; this distinction is relevant to the design of the API. The API documentation should indicate when JSON objects are used as maps.</p><p>The keys of a map do not have to obey the naming guidelines for property names. Map keys may contain any Unicode characters. Clients can access these properties using the square bracket notation familiar for maps (for example, <code>result.thumbnails["72"]</code>).</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
// The "address" property is a sub-object
|
// The "address" property is a sub-object
|
||||||
|
@ -150,7 +150,7 @@ Certain property names are reserved for consistent use across services.
|
||||||
Array types should have plural property names. All other property names should be singular.
|
Array types should have plural property names. All other property names should be singular.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Arrays usually contain multiple items, and a plural property name reflects this. An example of this can be seen in the reserved names below. The "items" property name is plural because it represents an array of item objects. Most of the other fields are singular.</p><p>There may be exceptions to this, especially when referring to numeric property values. For example, in the reserved names, "totalItems" makes more sense than "totalItem". However, technically, this is not violating the style guide, since "totalItems" can be viewed as "totalOfItems", where "total" is singular (as per the style guide), and "OfItems" serves to qualify the total. The field name could also be changed to "itemCount" to look singular.</p>
|
<p>Arrays usually contain multiple items, and a plural property name reflects this. An example of this can be seen in the reserved names below. The <code>items</code> property name is plural because it represents an array of item objects. Most of the other fields are singular.</p><p>There may be exceptions to this, especially when referring to numeric property values. For example, in the reserved names, <code>totalItems</code> makes more sense than <code>totalItem</code>. However, technically, this is not violating the style guide, since <code>totalItems</code> can be viewed as <code>totalOfItems</code>, where <code>total</code> is singular (as per the style guide), and <code>OfItems</code> serves to qualify the total. The field name could also be changed to <code>itemCount</code> to look singular.</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
// Singular
|
// Singular
|
||||||
|
@ -168,7 +168,7 @@ Array types should have plural property names. All other property names should
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Naming Conflicts">
|
<STYLEPOINT title="Naming Conflicts">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Avoid naming conflicts by choosing a new property name, or versioning the API.
|
Avoid naming conflicts by choosing a new property name or versioning the API.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>New properties may be added to the reserved list in the future. There is no concept of JSON namespacing. If there is a naming conflict, these can usually be resolved by choosing a new property name or by versioning. For example, suppose we start with the following JSON object:</p>
|
<p>New properties may be added to the reserved list in the future. There is no concept of JSON namespacing. If there is a naming conflict, these can usually be resolved by choosing a new property name or by versioning. For example, suppose we start with the following JSON object:</p>
|
||||||
|
@ -182,7 +182,7 @@ Avoid naming conflicts by choosing a new property name, or versioning the API.
|
||||||
}
|
}
|
||||||
|
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
<p>If in the future we wish to make "ingredients" a reserved word, we can do one of two things:</p><p>1) Choose a different name:</p>
|
<p>If in the future we wish to make <code>ingredients</code> a reserved word, we can do one of two things:</p><p>1) Choose a different name:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"apiVersion": "1.0",
|
"apiVersion": "1.0",
|
||||||
|
@ -212,7 +212,7 @@ Avoid naming conflicts by choosing a new property name, or versioning the API.
|
||||||
<CATEGORY title="Property Value Guidelines">
|
<CATEGORY title="Property Value Guidelines">
|
||||||
<STYLEPOINT title="Property Value Format">
|
<STYLEPOINT title="Property Value Format">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Property values must be Unicode booleans, numbers, strings, objects, arrays, and <code>null</code>.
|
Property values must be Unicode booleans, numbers, strings, objects, arrays, or <code>null</code>.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The spec at <a href="http://www.json.org">JSON.org</a> specifies exactly what type of data is allowed in a property value. This includes Unicode booleans, numbers, strings, objects, arrays, and <code>null</code>. JavaScript expressions are not allowed. APIs should support that spec for all values, and should choose the data type most appropriate for a particular property (numbers to represent numbers, etc.).</p><p>Good:</p>
|
<p>The spec at <a href="http://www.json.org">JSON.org</a> specifies exactly what type of data is allowed in a property value. This includes Unicode booleans, numbers, strings, objects, arrays, and <code>null</code>. JavaScript expressions are not allowed. APIs should support that spec for all values, and should choose the data type most appropriate for a particular property (numbers to represent numbers, etc.).</p><p>Good:</p>
|
||||||
|
@ -223,7 +223,7 @@ Property values must be Unicode booleans, numbers, strings, objects, arrays, and
|
||||||
"answerToLife": 42, // number
|
"answerToLife": 42, // number
|
||||||
"name": "Bart", // string
|
"name": "Bart", // string
|
||||||
"moreData": {}, // object
|
"moreData": {}, // object
|
||||||
"anArray": [] // array
|
"things": [] // array
|
||||||
}
|
}
|
||||||
|
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
|
@ -239,17 +239,19 @@ Property values must be Unicode booleans, numbers, strings, objects, arrays, and
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Empty/Null Property Values">
|
<STYLEPOINT title="Empty/Null Property Values">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
If a property is optional or has an empty/null value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.
|
Consider removing empty or <code>null</code> values.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>If a property is optional or has an empty/null value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.</p>
|
<p>If a property is optional or has an empty or <code>null</code> value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"volume": 10,
|
"volume": 10,
|
||||||
|
|
||||||
// Even though the "balance" property's value is zero, it should be left in,
|
// Even though the "balance" property's value is zero, it should be left in,
|
||||||
// since "0" signifies "even balance" (the value could be "-1" for left
|
// since "0" signifies "even balance" (the value could be "-1" for left
|
||||||
// balance and "+1" for right balance.
|
// balance and "+1" for right balance.
|
||||||
"balance": 0,
|
"balance": 0,
|
||||||
|
|
||||||
// The "currentlyPlaying" property can be left out since it is null.
|
// The "currentlyPlaying" property can be left out since it is null.
|
||||||
// "currentlyPlaying": null
|
// "currentlyPlaying": null
|
||||||
}
|
}
|
||||||
|
@ -273,7 +275,7 @@ public enum Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
<p>JSON Object:</p>
|
<p>JSON object:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"color": "WHITE"
|
"color": "WHITE"
|
||||||
|
@ -332,7 +334,7 @@ Latitudes/Longitudes should be formatted as recommended by ISO 6709.
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
<CATEGORY title="JSON Structure & Reserved Property Names">
|
<CATEGORY title="JSON Structure & Reserved Property Names">
|
||||||
<p>In order to maintain a consistent interface across APIs, JSON objects should follow the structure outlined below. This structure applies to both requests and responses made with JSON. Within this structure, there are certain property names that are reserved for specific uses. These properties are NOT required; in other words, each reserved property may appear zero or one time. But if a service needs these properties, this naming convention is recommend. Here is a schema of the JSON structure, represented in <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Forderly-json.org%2F">Orderly</a> format (which in turn can be compiled into a <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Fjson-schema.org%2F">JSONSchema</a>). You can few examples of the JSON structure at the end of this guide.</p>
|
<p>In order to maintain a consistent interface across APIs, JSON objects should follow the structure outlined below. This structure applies to both requests and responses made with JSON. Within this structure, there are certain property names that are reserved for specific uses. These properties are NOT required; in other words, each reserved property may appear zero or one times. But if a service needs these properties, this naming convention is recommend. Here is a schema of the JSON structure, represented in <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Forderly-json.org%2F">Orderly</a> format (which in turn can be compiled into a <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Fjson-schema.org%2F">JSONSchema</a>). You can few examples of the JSON structure at the end of this guide.</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
object {
|
object {
|
||||||
string apiVersion?;
|
string apiVersion?;
|
||||||
|
@ -396,7 +398,7 @@ object {
|
||||||
Property Value Type: string<br />Parent: -
|
Property Value Type: string<br />Parent: -
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Represents the desired version of the service API in a request, and the version of the service API that's served in the response. "apiVersion" should always be present. This is not related to the version of the data. Versioning of data should be handled through some other mechanism such as etags.</p><p>Example:</p>
|
<p>Represents the desired version of the service API in a request, and the version of the service API that's served in the response. <code>apiVersion</code> should always be present. This is not related to the version of the data. Versioning of data should be handled through some other mechanism such as etags.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{ "apiVersion": "2.1" }
|
{ "apiVersion": "2.1" }
|
||||||
|
|
||||||
|
@ -408,7 +410,7 @@ Property Value Type: string<br />Parent: -
|
||||||
Property Value Type: string<br />Parent: -
|
Property Value Type: string<br />Parent: -
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Client sets this value and server echos data in the response. This is useful in JSON-P and batch situations , where the user can use the "context" to correlate responses with requests. This property is a top-level property because the "context" should present regardless of whether the response was successful or an error. "Context" differs from "id" in that "context" is specified by the user while "id" is assigned by the service.</p><p>Example:</p><p>Request #1:</p>
|
<p>Client sets this value and server echos data in the response. This is useful in JSON-P and batch situations , where the user can use the <code>context</code> to correlate responses with requests. This property is a top-level property because the <code>context</code> should present regardless of whether the response was successful or an error. <code>context</code> differs from <code>id</code> in that <code>context</code> is specified by the user while <code>id</code> is assigned by the service.</p><p>Example:</p><p>Request #1:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
http://www.google.com/myapi?context=bart
|
http://www.google.com/myapi?context=bart
|
||||||
|
|
||||||
|
@ -438,7 +440,7 @@ http://www.google.com/myapi?context=lisa
|
||||||
}
|
}
|
||||||
|
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
<p>Common JavaScript handler code to process both response:</p>
|
<p>Common JavaScript handler code to process both responses:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
function handleResponse(response) {
|
function handleResponse(response) {
|
||||||
if (response.result.context == "bart") {
|
if (response.result.context == "bart") {
|
||||||
|
@ -468,7 +470,7 @@ Property Value Type: string<br />Parent: -
|
||||||
Property Value Type: string<br />Parent: -
|
Property Value Type: string<br />Parent: -
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Represents the operation to perform, or that was performed, on the data. In the case of a JSON request, the "method" property can be used to indicate which operation to perform on the data. In the case of a JSON response, the "method" property can indicate the operation performed on the data.</p><p>One example of this is in JSON-RPC requests, where "method" indicates the operation to perform on the "params" property:</p>
|
<p>Represents the operation to perform, or that was performed, on the data. In the case of a JSON request, the <code>method</code> property can be used to indicate which operation to perform on the data. In the case of a JSON response, the <code>method</code> property can indicate the operation performed on the data.</p><p>One example of this is in JSON-RPC requests, where <code>method</code> indicates the operation to perform on the <code>params</code> property:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"method": "people.get",
|
"method": "people.get",
|
||||||
|
@ -486,7 +488,7 @@ Property Value Type: string<br />Parent: -
|
||||||
Property Value Type: object<br />Parent: -
|
Property Value Type: object<br />Parent: -
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>This object serves as a map of input parameters to send to an RPC request. It can be used in conjunction with the "method" property to execute an RPC function. If an RPC function does not need parameters, this property can be omitted.</p><p>Example:</p>
|
<p>This object serves as a map of input parameters to send to an RPC request. It can be used in conjunction with the <code>method</code> property to execute an RPC function. If an RPC function does not need parameters, this property can be omitted.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"method": "people.get",
|
"method": "people.get",
|
||||||
|
@ -504,7 +506,7 @@ Property Value Type: object<br />Parent: -
|
||||||
Property Value Type: object<br />Parent: -
|
Property Value Type: object<br />Parent: -
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Container for all the data from a response. This property itself has many reserved property names, which are described below. Services are free to add their own data to this object. A JSON response should contain either a "data" object or an "error" object, but not both. If both "data" and "error" are present, the "error" object takes precedence.</p>
|
<p>Container for all the data from a response. This property itself has many reserved property names, which are described below. Services are free to add their own data to this object. A JSON response should contain either a <code>data</code> object or an <code>error</code> object, but not both. If both <code>data</code> and <code>error</code> are present, the <code>error</code> object takes precedence.</p>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="error">
|
<STYLEPOINT title="error">
|
||||||
|
@ -512,7 +514,7 @@ Property Value Type: object<br />Parent: -
|
||||||
Property Value Type: object<br />Parent: -
|
Property Value Type: object<br />Parent: -
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Indicates that an error has occurred, with details about the error. The error format supports either one or more errors returned from the service. A JSON response should contain either a "data" object or an "error" object, but not both. If both "data" and "error" are present, the "error" object takes precedence.</p><p>Example:</p>
|
<p>Indicates that an error has occurred, with details about the error. The error format supports either one or more errors returned from the service. A JSON response should contain either a <code>data</code> object or an <code>error</code> object, but not both. If both <code>data</code> and <code>error</code> are present, the <code>error</code> object takes precedence.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"apiVersion": "2.0",
|
"apiVersion": "2.0",
|
||||||
|
@ -523,7 +525,7 @@ Property Value Type: object<br />Parent: -
|
||||||
"domain": "Calendar",
|
"domain": "Calendar",
|
||||||
"reason": "ResourceNotFoundException",
|
"reason": "ResourceNotFoundException",
|
||||||
"message": "File Not Found
|
"message": "File Not Found
|
||||||
....}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,13 +534,13 @@ Property Value Type: object<br />Parent: -
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
<CATEGORY title="Reserved Property Names in the data object">
|
<CATEGORY title="Reserved Property Names in the data object">
|
||||||
<p>The "data" property of the JSON object may contain the following properties.</p>
|
<p>The <code>data</code> property of the JSON object may contain the following properties.</p>
|
||||||
<STYLEPOINT title="data.kind">
|
<STYLEPOINT title="data.kind">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Property Value Type: string<br />Parent: <code>data</code>
|
Property Value Type: string<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The "kind" property serves as a guide to what type of information this particular object stores. It can be present at the "data" level, or at the "items" level, or in any object where its helpful to distinguish between various types of objects. If the "kind" object is present, it should be the first property in the object (See the "Property Ordering" section below for more details).</p><p>Example:</p>
|
<p>The <code>kind</code> property serves as a guide to what type of information this particular object stores. It can be present at the <code>data</code> level, or at the <code>items</code> level, or in any object where its helpful to distinguish between various types of objects. If the <code>kind</code> object is present, it should be the first property in the object (See the "Property Ordering" section below for more details).</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
// "Kind" indicates an "album" in the Picasa API.
|
// "Kind" indicates an "album" in the Picasa API.
|
||||||
{"data": {"kind": "album"}}
|
{"data": {"kind": "album"}}
|
||||||
|
@ -582,7 +584,7 @@ Property Value Type: string<br />Parent: <code>data</code>
|
||||||
Property Value Type: string<br />Parent: <code>data</code>
|
Property Value Type: string<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>A globally unique string used to reference the object. The specific details of the "id" property are left up to the service.</p><p>Example:</p>
|
<p>A globally unique string used to reference the object. The specific details of the <code>id</code> property are left up to the service.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{"data": {"id": "12345"}}
|
{"data": {"id": "12345"}}
|
||||||
|
|
||||||
|
@ -612,7 +614,7 @@ Property Value Type: string (formatted as specified in BCP 47)<br />Parent: <cod
|
||||||
Property Value Type: string (formatted as specified in RFC 3339)<br />Parent: <code>data</code>
|
Property Value Type: string (formatted as specified in RFC 3339)<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Indicates the last date/time (RFC 3339) the item was updated, as defined by the service.</p><p>Example:</p>
|
<p>Indicates the last date/time (<a href="http://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a>) the item was updated, as defined by the service.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{"data": {"updated": "2007-11-06T16:34:41.000Z"}}
|
{"data": {"updated": "2007-11-06T16:34:41.000Z"}}
|
||||||
|
|
||||||
|
@ -642,10 +644,10 @@ Property Value Type: boolean<br />Parent: <code>data (or any child element)</cod
|
||||||
Property Value Type: array<br />Parent: <code>data</code>
|
Property Value Type: array<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The property name "items" is reserved to represent an array of items (for example, photos in Picasa, videos in YouTube). This construct is intended to provide a standard location for collections related to the current result. For example, the JSON output could be plugged into a generic pagination system that knows to page on the "items" array. If "items" exists, it should be the last property in the "data" object (See the "Property Ordering" section below for more details).</p><p>Example:</p>
|
<p>The property name <code>items</code> is reserved to represent an array of items (for example, photos in Picasa, videos in YouTube). This construct is intended to provide a standard location for collections related to the current result. For example, the JSON output could be plugged into a generic pagination system that knows to page on the <code>items</code> array. If <code>items</code> exists, it should be the last property in the <code>data</code> object (See the "Property Ordering" section below for more details).</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data" {
|
"data": {
|
||||||
"items": [
|
"items": [
|
||||||
{ /* Object #1 */ },
|
{ /* Object #1 */ },
|
||||||
{ /* Object #2 */ },
|
{ /* Object #2 */ },
|
||||||
|
@ -659,13 +661,13 @@ Property Value Type: array<br />Parent: <code>data</code>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
<CATEGORY title="Reserved Property Names for Paging">
|
<CATEGORY title="Reserved Property Names for Paging">
|
||||||
<p>The following properties are located in the "data" object, and are related to paging items. Some of the language and concepts are borrowed from the <a href="TDOD">OpenSearch specification</a>. The paging properties listed below allows users to page based on number of items. However some services may wish to offer page-based paging. For example, rather than jump to item number 200, some services may request page number 20. For these cases, two page-based properties have been added: "pageIndex" and "totalPages". An example of how to use these properties to implement paging can be found at the end of this guide.</p>
|
<p>The following properties are located in the <code>data</code> object, and help page through a list of items. Some of the language and concepts are borrowed from the <a href="http://www.opensearch.org/Home">OpenSearch specification</a>.</p><p>The paging properties below allow for various styles of paging, including:</p><ul><li>Previous/Next paging - Allows user's to move forward and backward through a list, one page at a time. The <code>nextLink</code> and <code>previousLink</code> properties (described in the "Reserved Property Names for Links" section below) are used for this style of paging.</li><li>Index-based paging - Allows user's to jump directly to a specific item position within a list of items. For example, to load 10 items starting at item 200, the developer may point the user to a url with the query string <code>?startIndex=200</code>.</li><li>Page-based paging - Allows user's to jump directly to a specific page within the items. This is similar to index-based paging, but saves the developer the extra step of having to calculate the item index for a new page of items. For example, rather than jump to item number 200, the developer could jump to page 20. The urls during page-based paging could use the query string <code>?page=1</code> or <code>?page=20</code>. The <code>pageIndex</code> and <code>totalPages</code> properties are used for this style of paging.</li></ul><p>An example of how to use these properties to implement paging can be found at the end of this guide.</p>
|
||||||
<STYLEPOINT title="data.currentItemCount">
|
<STYLEPOINT title="data.currentItemCount">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Property Value Type: integer<br />Parent: <code>data</code>
|
Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The number of items in this result set. Should be equivalent to items.length, and is provided as a convenience property. Say for example a developer requests a set of search items, and asks for 10 items per page. The total set of that search has 14 total items. The first page of items will have 10 items in it, so both "itemsPerPage" and "currentItemCount" will equal "10". The next page of items will have the remaining 4 items; "itemsPerPage" will still be "10", but "currentItemCount" will be "4".</p><p>Example:</p>
|
<p>The number of items in this result set. Should be equivalent to items.length, and is provided as a convenience property. For example, suppose a developer requests a set of search items, and asks for 10 items per page. The total set of that search has 14 total items. The first page of items will have 10 items in it, so both <code>itemsPerPage</code> and <code>currentItemCount</code> will equal "10". The next page of items will have the remaining 4 items; <code>itemsPerPage</code> will still be "10", but <code>currentItemCount</code> will be "4".</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -683,7 +685,7 @@ Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
Property Value Type: integer<br />Parent: <code>data</code>
|
Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The number of items in the result. This is not necessarily the size of the data.items array; if we are viewing the last page of items, the size of data.items may be less than "itemsPerPage". However the size of data.items should not exceed "itemsPerPage".</p><p>Example:</p>
|
<p>The number of items in the result. This is not necessarily the size of the data.items array; if we are viewing the last page of items, the size of data.items may be less than <code>itemsPerPage</code>. However the size of data.items should not exceed <code>itemsPerPage</code>.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -699,7 +701,7 @@ Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
Property Value Type: integer<br />Parent: <code>data</code>
|
Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The index of the first item in data.items. For consistency, "startIndex" should be 1-based. For example, the first item in the first set of items should have a "startIndex" of 1. If the user requests the next set of data, the "startIndex" may be 10.</p><p>Example:</p>
|
<p>The index of the first item in data.items. For consistency, <code>startIndex</code> should be 1-based. For example, the first item in the first set of items should have a <code>startIndex</code> of 1. If the user requests the next set of data, the <code>startIndex</code> may be 10.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -715,7 +717,7 @@ Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
Property Value Type: integer<br />Parent: <code>data</code>
|
Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The total number of items available in this set. For example, if a user has 100 blog posts, the response may only contain 10 items, but the "totalItems" would be 100.</p><p>Example:</p>
|
<p>The total number of items available in this set. For example, if a user has 100 blog posts, the response may only contain 10 items, but the <code>totalItems</code> would be 100.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -731,7 +733,7 @@ Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
Property Value Type: string<br />Parent: <code>data</code>
|
Property Value Type: string<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>A uri template indicating how users can calculate subsequent paging links. The uri template also has some reserved variable names: {index} representing the item number to load, and {pageIndex}, representing the page number to load.</p><p>Example:</p>
|
<p>A URI template indicating how users can calculate subsequent paging links. The URI template also has some reserved variable names: <code>{index}</code> representing the item number to load, and <code>{pageIndex}</code>, representing the page number to load.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -747,7 +749,7 @@ Property Value Type: string<br />Parent: <code>data</code>
|
||||||
Property Value Type: integer<br />Parent: <code>data</code>
|
Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The index of the current page of items. For consistency, "pageIndex" should be 1-based. For example, the first page of items has a "pageIndex" of 1. "pageIndex" can also be calculated from the item-based paging properties: "pageIndex" = floor(startIndex / itemsPerPage) + 1.</p><p>Example:</p>
|
<p>The index of the current page of items. For consistency, <code>pageIndex</code> should be 1-based. For example, the first page of items has a <code>pageIndex</code> of 1. <code>pageIndex</code> can also be calculated from the item-based paging properties: <code>pageIndex = floor(startIndex / itemsPerPage) + 1</code>.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -763,7 +765,7 @@ Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
Property Value Type: integer<br />Parent: <code>data</code>
|
Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The total number of pages in the result set. "totalPages" can also be calculated from the item-based paging properties above: "totalPages" = ceiling(totalItems / itemsPerPage).</p><p>Example:</p>
|
<p>The total number of pages in the result set. <code>totalPages</code> can also be calculated from the item-based paging properties above: <code>totalPages = ceiling(totalItems / itemsPerPage)</code>.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -776,13 +778,13 @@ Property Value Type: integer<br />Parent: <code>data</code>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
<CATEGORY title="Reserved Property Names for Links">
|
<CATEGORY title="Reserved Property Names for Links">
|
||||||
<p>The following properties are located in the "data" object, and represent references to other resources. There are two forms of link properties: 1) objects, which can contain any sort of reference (such as a JSON-RPC object), and 2) uri strings, which represent uris to resources (and will always be suffixed with "Link").</p>
|
<p>The following properties are located in the <code>data</code> object, and represent references to other resources. There are two forms of link properties: 1) objects, which can contain any sort of reference (such as a JSON-RPC object), and 2) URI strings, which represent URIs to resources (and will always be suffixed with "Link").</p>
|
||||||
<STYLEPOINT title="data.self / data.selfLink">
|
<STYLEPOINT title="data.self / data.selfLink">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Property Value Type: object / string<br />Parent: <code>data</code>
|
Property Value Type: object / string<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The self link can be used to retrieve the item's data. For example, in a list of a user's Picasa album, each album object in the "items" array could contain a "selfLink" that can be used to retrieve data related to that particular album.</p><p>Example:</p>
|
<p>The self link can be used to retrieve the item's data. For example, in a list of a user's Picasa album, each album object in the <code>items</code> array could contain a <code>selfLink</code> that can be used to retrieve data related to that particular album.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -816,7 +818,7 @@ Property Value Type: object / string<br />Parent: <code>data</code>
|
||||||
Property Value Type: object / string<br />Parent: <code>data</code>
|
Property Value Type: object / string<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The next link indicates how more data can be retrieved. It points to the location to load the next set of data. It can be used in conjunction with the itemsPerPage, startIndex and totalItems properties in order to page through data.</p><p>Example:</p>
|
<p>The next link indicates how more data can be retrieved. It points to the location to load the next set of data. It can be used in conjunction with the <code>itemsPerPage</code>, <code>startIndex</code> and <code>totalItems</code> properties in order to page through data.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -833,7 +835,7 @@ Property Value Type: object / string<br />Parent: <code>data</code>
|
||||||
Property Value Type: object / string<br />Parent: <code>data</code>
|
Property Value Type: object / string<br />Parent: <code>data</code>
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The previous link indicates how more data can be retrieved. It points to the location to load the previous set of data. It can be used in conjunction with the itemsPerPage, startIndex and totalItems properties in order to page through data.</p><p>Example:</p>
|
<p>The previous link indicates how more data can be retrieved. It points to the location to load the previous set of data. It can be used in conjunction with the <code>itemsPerPage</code>, <code>startIndex</code> and <code>totalItems</code> properties in order to page through data.</p><p>Example:</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
|
@ -847,7 +849,7 @@ Property Value Type: object / string<br />Parent: <code>data</code>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
<CATEGORY title="Reserved Property Names in the error object">
|
<CATEGORY title="Reserved Property Names in the error object">
|
||||||
<p>The "error" property of the JSON object may contain the following properties.</p>
|
<p>The <code>error</code> property of the JSON object may contain the following properties.</p>
|
||||||
<STYLEPOINT title="error.code">
|
<STYLEPOINT title="error.code">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Property Value Type: integer<br />Parent: <code>error</code>
|
Property Value Type: integer<br />Parent: <code>error</code>
|
||||||
|
@ -1014,12 +1016,12 @@ Property Value Type: string<br />Parent: <code>error.errors</code>
|
||||||
<code>kind</code> should be the first property
|
<code>kind</code> should be the first property
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>Suppose a parser is responsible for parsing a raw JSON stream into a specific object. The "kind" property guides the parser to instantiate the appropriate object. Therefore it should be the first property in the JSON object. This only applies when objects have a "kind" property (usually found in the "data" and "items" properties).</p>
|
<p>Suppose a parser is responsible for parsing a raw JSON stream into a specific object. The <code>kind</code> property guides the parser to instantiate the appropriate object. Therefore it should be the first property in the JSON object. This only applies when objects have a <code>kind</code> property (usually found in the <code>data</code> and <code>items</code> properties).</p>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Items Property">
|
<STYLEPOINT title="Items Property">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
<code>items</code> should be the last property in the "data" object
|
<code>items</code> should be the last property in the <code>data</code> object
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>This allows all of the collection's properties to be read before reading each individual item. In cases where there are a lot of items, this avoids unnecessarily parsing those items when the developer only needs fields from the data.</p>
|
<p>This allows all of the collection's properties to be read before reading each individual item. In cases where there are a lot of items, this avoids unnecessarily parsing those items when the developer only needs fields from the data.</p>
|
||||||
|
@ -1052,7 +1054,7 @@ Property Value Type: string<br />Parent: <code>error.errors</code>
|
||||||
<CATEGORY title="Examples">
|
<CATEGORY title="Examples">
|
||||||
<STYLEPOINT title="YouTube JSON API">
|
<STYLEPOINT title="YouTube JSON API">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Here's an example of the YouTube JSON API's response object.
|
Here's an example of the YouTube JSON API's response object. You can learn more about YouTube's JSON API here: <a href="http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html">http://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html</a>.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
|
@ -1148,7 +1150,7 @@ A list of reserved JavaScript words that should be avoided in property names.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>The words below are reserved by the JavaScript language and cannot be referred to using dot notation. The list represents best knowledge of keywords at this time; the list may change or vary based on your specific execution environment.</p><p>From the <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Fwww.ecma-international.org%2Fpublications%2Fstandards%2FEcma-262.htm">ECMAScript Language Specification 5th Edition</a></p>
|
<p>The words below are reserved by the JavaScript language and cannot be referred to using dot notation. The list represents best knowledge of keywords at this time; the list may change or vary based on your specific execution environment.</p><p>From the <a href="http://www.google.com/url?sa=D&q=http%3A%2F%2Fwww.ecma-international.org%2Fpublications%2Fstandards%2FEcma-262.htm">ECMAScript Language Specification 5th Edition</a></p>
|
||||||
<CODE_SNIPPET>
|
<BAD_CODE_SNIPPET>
|
||||||
abstract
|
abstract
|
||||||
boolean break byte
|
boolean break byte
|
||||||
case catch char class const continue
|
case catch char class const continue
|
||||||
|
@ -1166,7 +1168,7 @@ this throw throws transient true try typeof
|
||||||
var volatile void
|
var volatile void
|
||||||
while with
|
while with
|
||||||
yield
|
yield
|
||||||
</CODE_SNIPPET>
|
</BAD_CODE_SNIPPET>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user