blob: 3a2ac2543447d0c62fd19b87733228be66db9c8c [file] [log] [blame]
monsurf07658c2010-02-22 22:39:56 +00001<?xml version="1.0"?>
2<?xml-stylesheet type="text/xsl" href="styleguide.xsl"?>
3<GUIDE title="Google JSON Style Guide">
4
5<p align="right">
6Revision 0.9
7</p>
8
9<address>
10</address>
11
12<OVERVIEW>
13<CATEGORY title="Important Note">
14<STYLEPOINT title="Display Hidden Details in this Guide">
15<SUMMARY>
16This style guide contains many details that are initially hidden from view. They are marked by the triangle icon, which you see here on your left. Click it now. You should see "Hooray" appear below.
17</SUMMARY>
18<BODY>
19<p>Hooray! Now you know you can expand points to get more details. Alternatively, there's an "expand all" at the top of this document.</p>
20</BODY>
21</STYLEPOINT>
22</CATEGORY>
23<CATEGORY title="Introduction">
24<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>
25</CATEGORY>
26<CATEGORY title="Definitions">
monsur8643ca82010-02-25 18:45:27 +000027<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>
monsurf07658c2010-02-22 22:39:56 +000028<CODE_SNIPPET>
29{
30 // The name/value pair together is a "property".
monsur8643ca82010-02-25 18:45:27 +000031 "propertyName": "propertyValue"
monsurf07658c2010-02-22 22:39:56 +000032}
33
34</CODE_SNIPPET>
35<p>Javascript's <code>number</code> type encompasses all floating-point numbers, which is a broad designation. In this guide, <code>number</code> will refer to JavaScript's <code>number</code> type, while <code>integer</code> will refer to integers.</p>
36</CATEGORY>
37</OVERVIEW>
38<CATEGORY title="General Guidelines">
39<STYLEPOINT title="Comments">
40<SUMMARY>
41No comments in JSON objects.
42</SUMMARY>
43<BODY>
44<p>Comments should not be included in JSON objects. Some of the examples in this style guide include comments. However this is only to clarify the examples.</p>
45<BAD_CODE_SNIPPET>
46{
47 // You may see comments in the examples below,
48 // But don't include comments in your JSON.
monsur8643ca82010-02-25 18:45:27 +000049 "propertyName": "propertyValue"
monsurf07658c2010-02-22 22:39:56 +000050}
51
52</BAD_CODE_SNIPPET>
53</BODY>
54</STYLEPOINT>
55<STYLEPOINT title="Double Quotes">
56<SUMMARY>
57Use double quotes.
58</SUMMARY>
59<BODY>
monsur8643ca82010-02-25 18:45:27 +000060<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>
monsurf07658c2010-02-22 22:39:56 +000061</BODY>
62</STYLEPOINT>
63<STYLEPOINT title="Flattened data vs Structured Hierarchy">
64<SUMMARY>
monsur8643ca82010-02-25 18:45:27 +000065Data should not be arbitrarily grouped for convenience.
monsurf07658c2010-02-22 22:39:56 +000066</SUMMARY>
67<BODY>
68<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>
69<p>Flattened Address:</p>
70<CODE_SNIPPET>
71{
monsur8643ca82010-02-25 18:45:27 +000072 "company": "Google",
Ackermann Yuriy79692902016-04-01 21:41:34 +130073 "website": "https://www.google.com/",
monsur8643ca82010-02-25 18:45:27 +000074 "addressLine1": "111 8th Ave",
75 "addressLine2": "4th Floor",
76 "state": "NY",
77 "city": "New York",
78 "zip": "10011"
monsurf07658c2010-02-22 22:39:56 +000079}
80</CODE_SNIPPET>
81<p>Structured Address:</p>
82<CODE_SNIPPET>
83{
monsur8643ca82010-02-25 18:45:27 +000084 "company": "Google",
Ackermann Yuriy79692902016-04-01 21:41:34 +130085 "website": "https://www.google.com/",
monsur8643ca82010-02-25 18:45:27 +000086 "address": {
87 "line1": "111 8th Ave",
88 "line2": "4th Floor",
89 "state": "NY",
90 "city": "New York",
91 "zip": "10011"
monsurf07658c2010-02-22 22:39:56 +000092 }
93}
94</CODE_SNIPPET>
95</BODY>
96</STYLEPOINT>
97</CATEGORY>
98<CATEGORY title="Property Name Guidelines">
99<STYLEPOINT title="Property Name Format">
100<SUMMARY>
101Choose meaningful property names.
102</SUMMARY>
103<BODY>
monsur8643ca82010-02-25 18:45:27 +0000104<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>
monsurf07658c2010-02-22 22:39:56 +0000105<CODE_SNIPPET>
106{
monsur8643ca82010-02-25 18:45:27 +0000107 "thisPropertyIsAnIdentifier": "identifier value"
monsurf07658c2010-02-22 22:39:56 +0000108}
109
110</CODE_SNIPPET>
111</BODY>
112</STYLEPOINT>
113<STYLEPOINT title="Key Names in JSON Maps">
114<SUMMARY>
115JSON maps can use any Unicode character in key names.
116</SUMMARY>
117<BODY>
monsur8643ca82010-02-25 18:45:27 +0000118<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>
monsurf07658c2010-02-22 22:39:56 +0000119<CODE_SNIPPET>
120{
121 // The "address" property is a sub-object
122 // holding the parts of an address.
123 "address": {
124 "addressLine1": "123 Anystreet",
125 "city": "Anytown",
126 "state": "XX",
127 "zip": "00000"
128 },
129 // The "thumbnails" property is a map that maps
130 // a pixel size to the thumbnail url of that size.
monsur8643ca82010-02-25 18:45:27 +0000131 "thumbnails": {
132 "72": "http://url.to.72px.thumbnail",
133 "144": "http://url.to.144px.thumbnail"
monsurf07658c2010-02-22 22:39:56 +0000134 }
135}
136
137</CODE_SNIPPET>
138</BODY>
139</STYLEPOINT>
140<STYLEPOINT title="Reserved Property Names">
141<SUMMARY>
142Certain property names are reserved for consistent use across services.
143</SUMMARY>
144<BODY>
145<p>Details about reserved property names, along with the full list, can be found later on in this guide. Services should avoid using these property names for anything other than their defined semantics.</p>
146</BODY>
147</STYLEPOINT>
148<STYLEPOINT title="Singular vs Plural Property Names">
149<SUMMARY>
150Array types should have plural property names. All other property names should be singular.
151</SUMMARY>
152<BODY>
monsur8643ca82010-02-25 18:45:27 +0000153<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>
monsurf07658c2010-02-22 22:39:56 +0000154<CODE_SNIPPET>
155{
156 // Singular
monsur8643ca82010-02-25 18:45:27 +0000157 "author": "lisa",
monsurf07658c2010-02-22 22:39:56 +0000158 // An array of siblings, plural
monsur8643ca82010-02-25 18:45:27 +0000159 "siblings": [ "bart", "maggie"],
monsurf07658c2010-02-22 22:39:56 +0000160 // "totalItem" doesn't sound right
monsur8643ca82010-02-25 18:45:27 +0000161 "totalItems": 10,
monsurf07658c2010-02-22 22:39:56 +0000162 // But maybe "itemCount" is better
163 "itemCount": 10,
164}
165
166</CODE_SNIPPET>
167</BODY>
168</STYLEPOINT>
169<STYLEPOINT title="Naming Conflicts">
170<SUMMARY>
monsur8643ca82010-02-25 18:45:27 +0000171Avoid naming conflicts by choosing a new property name or versioning the API.
monsurf07658c2010-02-22 22:39:56 +0000172</SUMMARY>
173<BODY>
174<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>
175<CODE_SNIPPET>
176{
monsur8643ca82010-02-25 18:45:27 +0000177 "apiVersion": "1.0",
178 "data": {
179 "recipeName": "pizza",
180 "ingredients": ["tomatoes", "cheese", "sausage"]
monsurf07658c2010-02-22 22:39:56 +0000181 }
182}
183
184</CODE_SNIPPET>
monsur8643ca82010-02-25 18:45:27 +0000185<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>
monsurf07658c2010-02-22 22:39:56 +0000186<CODE_SNIPPET>
187{
monsur8643ca82010-02-25 18:45:27 +0000188 "apiVersion": "1.0",
189 "data": {
190 "recipeName": "pizza",
191 "ingredientsData": "Some new property",
192 "ingredients": ["tomatoes", "cheese", "sausage"]
monsurf07658c2010-02-22 22:39:56 +0000193 }
194}
195
196</CODE_SNIPPET>
197<p>2) Rename the property on a major version boundary:</p>
198<CODE_SNIPPET>
199{
monsur8643ca82010-02-25 18:45:27 +0000200 "apiVersion": "2.0",
201 "data": {
202 "recipeName": "pizza",
203 "ingredients": "Some new property",
204 "recipeIngredients": ["tomatos", "cheese", "sausage"]
monsurf07658c2010-02-22 22:39:56 +0000205 }
206}
207
208</CODE_SNIPPET>
209</BODY>
210</STYLEPOINT>
211</CATEGORY>
212<CATEGORY title="Property Value Guidelines">
213<STYLEPOINT title="Property Value Format">
214<SUMMARY>
monsur8643ca82010-02-25 18:45:27 +0000215Property values must be Unicode booleans, numbers, strings, objects, arrays, or <code>null</code>.
monsurf07658c2010-02-22 22:39:56 +0000216</SUMMARY>
217<BODY>
218<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>
219<CODE_SNIPPET>
220{
221 "canPigsFly": null, // null
222 "areWeThereYet": false, // boolean
223 "answerToLife": 42, // number
224 "name": "Bart", // string
225 "moreData": {}, // object
monsur8643ca82010-02-25 18:45:27 +0000226 "things": [] // array
monsurf07658c2010-02-22 22:39:56 +0000227}
228
229</CODE_SNIPPET>
230<p>Bad:</p>
231<BAD_CODE_SNIPPET>
232{
233 "aVariableName": aVariableName, // Bad - JavaScript identifier
234 "functionFoo": function() { return 1; } // Bad - JavaScript function
235}
236
237</BAD_CODE_SNIPPET>
238</BODY>
239</STYLEPOINT>
240<STYLEPOINT title="Empty/Null Property Values">
241<SUMMARY>
monsur8643ca82010-02-25 18:45:27 +0000242Consider removing empty or <code>null</code> values.
monsurf07658c2010-02-22 22:39:56 +0000243</SUMMARY>
244<BODY>
monsur8643ca82010-02-25 18:45:27 +0000245<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>
monsurf07658c2010-02-22 22:39:56 +0000246<CODE_SNIPPET>
247{
monsur8643ca82010-02-25 18:45:27 +0000248 "volume": 10,
249
monsurf07658c2010-02-22 22:39:56 +0000250 // Even though the "balance" property's value is zero, it should be left in,
251 // since "0" signifies "even balance" (the value could be "-1" for left
252 // balance and "+1" for right balance.
monsur8643ca82010-02-25 18:45:27 +0000253 "balance": 0,
254
monsurf07658c2010-02-22 22:39:56 +0000255 // The "currentlyPlaying" property can be left out since it is null.
monsur8643ca82010-02-25 18:45:27 +0000256 // "currentlyPlaying": null
monsurf07658c2010-02-22 22:39:56 +0000257}
258
259</CODE_SNIPPET>
260</BODY>
261</STYLEPOINT>
262<STYLEPOINT title="Enum Values">
263<SUMMARY>
264Enum values should be represented as strings.
265</SUMMARY>
266<BODY>
267<p>As APIs grow, enum values may be added, removed or changed. Using strings as enum values ensures that downstream clients can gracefully handle changes to enum values.</p><p>Java code:</p>
268<CODE_SNIPPET>
269public enum Color {
270 WHITE,
271 BLACK,
272 RED,
273 YELLOW,
274 BLUE
275}
276
277</CODE_SNIPPET>
monsur8643ca82010-02-25 18:45:27 +0000278<p>JSON object:</p>
monsurf07658c2010-02-22 22:39:56 +0000279<CODE_SNIPPET>
280{
monsur8643ca82010-02-25 18:45:27 +0000281 "color": "WHITE"
monsurf07658c2010-02-22 22:39:56 +0000282}
283
284</CODE_SNIPPET>
285</BODY>
286</STYLEPOINT>
287</CATEGORY>
288<CATEGORY title="Property Value Data Types">
289<p>As mentioned above, property value types must be booleans, numbers, strings, objects, arrays, or <code>null</code>. However, it is useful define a set of standard data types when dealing with certain values. These data types will always be strings, but they will be formatted in a specific manner so that they can be easily parsed.</p>
290<STYLEPOINT title="Date Property Values">
291<SUMMARY>
292Dates should be formatted as recommended by RFC 3339.
293</SUMMARY>
294<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300295<p>Dates should be strings formatted as recommended by <a href="https://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a></p>
monsurf07658c2010-02-22 22:39:56 +0000296<CODE_SNIPPET>
297{
monsur8643ca82010-02-25 18:45:27 +0000298 "lastUpdate": "2007-11-06T16:34:41.000Z"
monsurf07658c2010-02-22 22:39:56 +0000299}
300
301</CODE_SNIPPET>
302</BODY>
303</STYLEPOINT>
304<STYLEPOINT title="Time Duration Property Values">
305<SUMMARY>
306Time durations should be formatted as recommended by ISO 8601.
307</SUMMARY>
308<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300309<p>Time duration values should be strings formatted as recommended by <a href="https://en.wikipedia.org/wiki/ISO_8601#Durations">ISO 8601</a>.</p>
monsurf07658c2010-02-22 22:39:56 +0000310<CODE_SNIPPET>
311{
312 // three years, six months, four days, twelve hours,
313 // thirty minutes, and five seconds
monsur8643ca82010-02-25 18:45:27 +0000314 "duration": "P3Y6M4DT12H30M5S"
monsurf07658c2010-02-22 22:39:56 +0000315}
316
317</CODE_SNIPPET>
318</BODY>
319</STYLEPOINT>
320<STYLEPOINT title="Latitude/Longitude Property Values">
321<SUMMARY>
322Latitudes/Longitudes should be formatted as recommended by ISO 6709.
323</SUMMARY>
324<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300325<p>Latitude/Longitude should be strings formatted as recommended by <a href="https://en.wikipedia.org/wiki/ISO_6709">ISO 6709</a>. Furthermore, they should favor the ±DD.DDDD±DDD.DDDD degrees format.</p>
monsurf07658c2010-02-22 22:39:56 +0000326<CODE_SNIPPET>
327{
328 // The latitude/longitude location of the statue of liberty.
monsur8643ca82010-02-25 18:45:27 +0000329 "statueOfLiberty": "+40.6894-074.0447"
monsurf07658c2010-02-22 22:39:56 +0000330}
331
332</CODE_SNIPPET>
333</BODY>
334</STYLEPOINT>
335</CATEGORY>
336<CATEGORY title="JSON Structure &amp; Reserved Property Names">
Ackermann Yuriy79692902016-04-01 21:41:34 +1300337<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="https://www.google.com/url?sa=D&amp;q=http%3A%2F%2Forderly-json.org%2F">Orderly</a> format (which in turn can be compiled into a <a href="https://www.google.com/url?sa=D&amp;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>
monsurf07658c2010-02-22 22:39:56 +0000338<CODE_SNIPPET>
339object {
340 string apiVersion?;
341 string context?;
342 string id?;
343 string method?;
344 object {
345 string id?
346 }* params?;
347 object {
348 string kind?;
349 string fields?;
350 string etag?;
351 string id?;
352 string lang?;
353 string updated?; # date formatted RFC 3339
354 boolean deleted?;
355 integer currentItemCount?;
356 integer itemsPerPage?;
357 integer startIndex?;
358 integer totalItems?;
359 integer pageIndex?;
360 integer totalPages?;
361 string pageLinkTemplate /^https?:/ ?;
362 object {}* next?;
363 string nextLink?;
364 object {}* previous?;
365 string previousLink?;
366 object {}* self?;
367 string selfLink?;
368 object {}* edit?;
369 string editLink?;
370 array [
371 object {}*;
372 ] items?;
373 }* data?;
374 object {
375 integer code?;
376 string message?;
377 array [
378 object {
379 string domain?;
380 string reason?;
381 string message?;
382 string location?;
383 string locationType?;
384 string extendedHelp?;
385 string sendReport?;
386 }*;
387 ] errors?;
388 }* error?;
389}*;
390
391</CODE_SNIPPET>
392<p>The JSON object has a few top-level properties, followed by either a <code>data</code> object or an <code>error</code> object, but not both. An explanation of each of these properties can be found below.</p>
393</CATEGORY>
394<CATEGORY title="Top-Level Reserved Property Names">
395<p>The top-level of the JSON object may contain the following properties.</p>
396<STYLEPOINT title="apiVersion">
397<SUMMARY>
398Property Value Type: string<br />Parent: -
399</SUMMARY>
400<BODY>
monsur8643ca82010-02-25 18:45:27 +0000401<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>
monsurf07658c2010-02-22 22:39:56 +0000402<CODE_SNIPPET>
monsur8643ca82010-02-25 18:45:27 +0000403{ "apiVersion": "2.1" }
monsurf07658c2010-02-22 22:39:56 +0000404
405</CODE_SNIPPET>
406</BODY>
407</STYLEPOINT>
408<STYLEPOINT title="context">
409<SUMMARY>
410Property Value Type: string<br />Parent: -
411</SUMMARY>
412<BODY>
monsur8643ca82010-02-25 18:45:27 +0000413<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>
monsurf07658c2010-02-22 22:39:56 +0000414<CODE_SNIPPET>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300415https://www.google.com/myapi?context=bart
monsurf07658c2010-02-22 22:39:56 +0000416
417</CODE_SNIPPET>
418<p>Request #2:</p>
419<CODE_SNIPPET>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300420https://www.google.com/myapi?context=lisa
monsurf07658c2010-02-22 22:39:56 +0000421
422</CODE_SNIPPET>
423<p>Response #1:</p>
424<CODE_SNIPPET>
425{
monsur8643ca82010-02-25 18:45:27 +0000426 "context": "bart",
427 "data": {
428 "items": []
429 }
monsurf07658c2010-02-22 22:39:56 +0000430}
431
432</CODE_SNIPPET>
433<p>Response #2:</p>
434<CODE_SNIPPET>
435{
monsur8643ca82010-02-25 18:45:27 +0000436 "context": "lisa",
437 "data": {
438 "items": []
439 }
monsurf07658c2010-02-22 22:39:56 +0000440}
441
442</CODE_SNIPPET>
monsur8643ca82010-02-25 18:45:27 +0000443<p>Common JavaScript handler code to process both responses:</p>
monsurf07658c2010-02-22 22:39:56 +0000444<CODE_SNIPPET>
445function handleResponse(response) {
446 if (response.result.context == "bart") {
447 // Update the "Bart" section of the page.
448 } else if (response.result.context == "lisa") {
449 // Update the "Lisa" section of the page.
450 }
451}
452
453</CODE_SNIPPET>
454</BODY>
455</STYLEPOINT>
456<STYLEPOINT title="id">
457<SUMMARY>
458Property Value Type: string<br />Parent: -
459</SUMMARY>
460<BODY>
461<p>A server supplied identifier for the response (regardless of whether the response is a success or an error). This is useful for correlating server logs with individual responses received at a client.</p><p>Example:</p>
462<CODE_SNIPPET>
monsur8643ca82010-02-25 18:45:27 +0000463{ "id": "1" }
monsurf07658c2010-02-22 22:39:56 +0000464
465</CODE_SNIPPET>
466</BODY>
467</STYLEPOINT>
468<STYLEPOINT title="method">
469<SUMMARY>
470Property Value Type: string<br />Parent: -
471</SUMMARY>
472<BODY>
monsur8643ca82010-02-25 18:45:27 +0000473<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>
monsurf07658c2010-02-22 22:39:56 +0000474<CODE_SNIPPET>
475{
monsur8643ca82010-02-25 18:45:27 +0000476 "method": "people.get",
477 "params": {
478 "userId": "@me",
479 "groupId": "@self"
monsurf07658c2010-02-22 22:39:56 +0000480 }
481}
482
483</CODE_SNIPPET>
484</BODY>
485</STYLEPOINT>
486<STYLEPOINT title="params">
487<SUMMARY>
488Property Value Type: object<br />Parent: -
489</SUMMARY>
490<BODY>
monsur8643ca82010-02-25 18:45:27 +0000491<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>
monsurf07658c2010-02-22 22:39:56 +0000492<CODE_SNIPPET>
493{
monsur8643ca82010-02-25 18:45:27 +0000494 "method": "people.get",
495 "params": {
496 "userId": "@me",
497 "groupId": "@self"
monsurf07658c2010-02-22 22:39:56 +0000498 }
499}
500
501</CODE_SNIPPET>
502</BODY>
503</STYLEPOINT>
504<STYLEPOINT title="data">
505<SUMMARY>
506Property Value Type: object<br />Parent: -
507</SUMMARY>
508<BODY>
monsur8643ca82010-02-25 18:45:27 +0000509<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>
monsurf07658c2010-02-22 22:39:56 +0000510</BODY>
511</STYLEPOINT>
512<STYLEPOINT title="error">
513<SUMMARY>
514Property Value Type: object<br />Parent: -
515</SUMMARY>
516<BODY>
monsur8643ca82010-02-25 18:45:27 +0000517<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>
monsurf07658c2010-02-22 22:39:56 +0000518<CODE_SNIPPET>
519{
monsur8643ca82010-02-25 18:45:27 +0000520 "apiVersion": "2.0",
521 "error": {
522 "code": 404,
523 "message": "File Not Found",
524 "errors": [{
monsurf07658c2010-02-22 22:39:56 +0000525 "domain": "Calendar",
526 "reason": "ResourceNotFoundException",
527 "message": "File Not Found
monsur8643ca82010-02-25 18:45:27 +0000528 }]
monsurf07658c2010-02-22 22:39:56 +0000529 }
530}
531
532</CODE_SNIPPET>
533</BODY>
534</STYLEPOINT>
535</CATEGORY>
536<CATEGORY title="Reserved Property Names in the data object">
monsur8643ca82010-02-25 18:45:27 +0000537<p>The <code>data</code> property of the JSON object may contain the following properties.</p>
monsurf07658c2010-02-22 22:39:56 +0000538<STYLEPOINT title="data.kind">
539<SUMMARY>
540Property Value Type: string<br />Parent: <code>data</code>
541</SUMMARY>
542<BODY>
monsur8643ca82010-02-25 18:45:27 +0000543<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>
monsurf07658c2010-02-22 22:39:56 +0000544<CODE_SNIPPET>
545// "Kind" indicates an "album" in the Picasa API.
546{"data": {"kind": "album"}}
547
548</CODE_SNIPPET>
549</BODY>
550</STYLEPOINT>
551<STYLEPOINT title="data.fields">
552<SUMMARY>
553Property Value Type: string<br />Parent: <code>data</code>
554</SUMMARY>
555<BODY>
556<p>Represents the fields present in the response when doing a partial GET, or the fields present in a request when doing a partial PATCH. This property should only exist during a partial GET/PATCH, and should not be empty.</p><p>Example:</p>
557<CODE_SNIPPET>
558{
monsur8643ca82010-02-25 18:45:27 +0000559 "data": {
monsurf07658c2010-02-22 22:39:56 +0000560 "kind": "user",
561 "fields": "author,id",
562 "id": "bart",
563 "author": "Bart"
564 }
565}
566
567</CODE_SNIPPET>
568</BODY>
569</STYLEPOINT>
570<STYLEPOINT title="data.etag">
571<SUMMARY>
572Property Value Type: string<br />Parent: <code>data</code>
573</SUMMARY>
574<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300575<p>Represents the etag for the response. Details about ETags in the GData APIs can be found here: <a href="https://code.google.com/apis/gdata/docs/2.0/reference.html#ResourceVersioning">https://code.google.com/apis/gdata/docs/2.0/reference.html#ResourceVersioning</a></p><p>Example:</p>
monsurf07658c2010-02-22 22:39:56 +0000576<CODE_SNIPPET>
577{"data": {"etag": "W/"C0QBRXcycSp7ImA9WxRVFUk.""}}
578
579</CODE_SNIPPET>
580</BODY>
581</STYLEPOINT>
582<STYLEPOINT title="data.id">
583<SUMMARY>
584Property Value Type: string<br />Parent: <code>data</code>
585</SUMMARY>
586<BODY>
monsur8643ca82010-02-25 18:45:27 +0000587<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>
monsurf07658c2010-02-22 22:39:56 +0000588<CODE_SNIPPET>
589{"data": {"id": "12345"}}
590
591</CODE_SNIPPET>
592</BODY>
593</STYLEPOINT>
594<STYLEPOINT title="data.lang">
595<SUMMARY>
596Property Value Type: string (formatted as specified in BCP 47)<br />Parent: <code>data (or any child element)</code>
597</SUMMARY>
598<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300599<p>Indicates the language of the rest of the properties in this object. This property mimics HTML's <code>lang</code> property and XML's <code>xml:lang</code> properties. The value should be a language value as defined in <a href="https://www.rfc-editor.org/rfc/bcp/bcp47.txt">BCP 47</a>. If a single JSON object contains data in multiple languages, the service is responsible for developing and documenting an appropriate location for the <code>lang</code> property.</p><p>Example:</p>
monsurf07658c2010-02-22 22:39:56 +0000600<CODE_SNIPPET>
601{"data": {
602 "items": [
603 { "lang": "en",
604 "title": "Hello world!" },
605 { "lang": "fr",
606 "title": "Bonjour monde!" }
607 ]}
608}
609</CODE_SNIPPET>
610</BODY>
611</STYLEPOINT>
612<STYLEPOINT title="data.updated">
613<SUMMARY>
614Property Value Type: string (formatted as specified in RFC 3339)<br />Parent: <code>data</code>
615</SUMMARY>
616<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +1300617<p>Indicates the last date/time (<a href="https://www.ietf.org/rfc/rfc3339.txt">RFC 3339</a>) the item was updated, as defined by the service.</p><p>Example:</p>
monsurf07658c2010-02-22 22:39:56 +0000618<CODE_SNIPPET>
619{"data": {"updated": "2007-11-06T16:34:41.000Z"}}
620
621</CODE_SNIPPET>
622</BODY>
623</STYLEPOINT>
624<STYLEPOINT title="data.deleted">
625<SUMMARY>
626Property Value Type: boolean<br />Parent: <code>data (or any child element)</code>
627</SUMMARY>
628<BODY>
629<p>A marker element, that, when present, indicates the containing entry is deleted. If deleted is present, its value must be <code>true</code>; a value of <code>false</code> can cause confusion and should be avoided.</p><p>Example:</p>
630<CODE_SNIPPET>
631{"data": {
632 "items": [
633 { "title": "A deleted entry",
634 "deleted": true
635 }
636 ]}
637}
638
639</CODE_SNIPPET>
640</BODY>
641</STYLEPOINT>
642<STYLEPOINT title="data.items">
643<SUMMARY>
644Property Value Type: array<br />Parent: <code>data</code>
645</SUMMARY>
646<BODY>
monsur8643ca82010-02-25 18:45:27 +0000647<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>
monsurf07658c2010-02-22 22:39:56 +0000648<CODE_SNIPPET>
649{
monsur8643ca82010-02-25 18:45:27 +0000650 "data": {
651 "items": [
monsurf07658c2010-02-22 22:39:56 +0000652 { /* Object #1 */ },
653 { /* Object #2 */ },
654 ...
655 ]
656 }
657}
658
659</CODE_SNIPPET>
660</BODY>
661</STYLEPOINT>
662</CATEGORY>
663<CATEGORY title="Reserved Property Names for Paging">
monsur8643ca82010-02-25 18:45:27 +0000664<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>
monsurf07658c2010-02-22 22:39:56 +0000665<STYLEPOINT title="data.currentItemCount">
666<SUMMARY>
667Property Value Type: integer<br />Parent: <code>data</code>
668</SUMMARY>
669<BODY>
monsur8643ca82010-02-25 18:45:27 +0000670<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>
monsurf07658c2010-02-22 22:39:56 +0000671<CODE_SNIPPET>
672{
673 "data": {
674 // "itemsPerPage" does not necessarily match "currentItemCount"
675 "itemsPerPage": 10,
676 "currentItemCount": 4
677 }
678}
679
680</CODE_SNIPPET>
681</BODY>
682</STYLEPOINT>
683<STYLEPOINT title="data.itemsPerPage">
684<SUMMARY>
685Property Value Type: integer<br />Parent: <code>data</code>
686</SUMMARY>
687<BODY>
monsur8643ca82010-02-25 18:45:27 +0000688<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>
monsurf07658c2010-02-22 22:39:56 +0000689<CODE_SNIPPET>
690{
691 "data": {
692 "itemsPerPage": 10
693 }
694}
695
696</CODE_SNIPPET>
697</BODY>
698</STYLEPOINT>
699<STYLEPOINT title="data.startIndex">
700<SUMMARY>
701Property Value Type: integer<br />Parent: <code>data</code>
702</SUMMARY>
703<BODY>
monsur8643ca82010-02-25 18:45:27 +0000704<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>
monsurf07658c2010-02-22 22:39:56 +0000705<CODE_SNIPPET>
706{
707 "data": {
708 "startIndex": 1
709 }
710}
711
712</CODE_SNIPPET>
713</BODY>
714</STYLEPOINT>
715<STYLEPOINT title="data.totalItems">
716<SUMMARY>
717Property Value Type: integer<br />Parent: <code>data</code>
718</SUMMARY>
719<BODY>
monsur8643ca82010-02-25 18:45:27 +0000720<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>
monsurf07658c2010-02-22 22:39:56 +0000721<CODE_SNIPPET>
722{
723 "data": {
724 "totalItems": 100
725 }
726}
727
728</CODE_SNIPPET>
729</BODY>
730</STYLEPOINT>
731<STYLEPOINT title="data.pagingLinkTemplate">
732<SUMMARY>
733Property Value Type: string<br />Parent: <code>data</code>
734</SUMMARY>
735<BODY>
monsur8643ca82010-02-25 18:45:27 +0000736<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>
monsurf07658c2010-02-22 22:39:56 +0000737<CODE_SNIPPET>
738{
739 "data": {
Ackermann Yuriy79692902016-04-01 21:41:34 +1300740 "pagingLinkTemplate": "https://www.google.com/search/hl=en&amp;q=chicago+style+pizza&amp;start={index}&amp;sa=N"
monsurf07658c2010-02-22 22:39:56 +0000741 }
742}
743
744</CODE_SNIPPET>
745</BODY>
746</STYLEPOINT>
747<STYLEPOINT title="data.pageIndex">
748<SUMMARY>
749Property Value Type: integer<br />Parent: <code>data</code>
750</SUMMARY>
751<BODY>
monsur8643ca82010-02-25 18:45:27 +0000752<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>
monsurf07658c2010-02-22 22:39:56 +0000753<CODE_SNIPPET>
754{
755 "data": {
monsur8643ca82010-02-25 18:45:27 +0000756 "pageIndex": 1
monsurf07658c2010-02-22 22:39:56 +0000757 }
758}
759
760</CODE_SNIPPET>
761</BODY>
762</STYLEPOINT>
763<STYLEPOINT title="data.totalPages">
764<SUMMARY>
765Property Value Type: integer<br />Parent: <code>data</code>
766</SUMMARY>
767<BODY>
monsur8643ca82010-02-25 18:45:27 +0000768<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>
monsurf07658c2010-02-22 22:39:56 +0000769<CODE_SNIPPET>
770{
771 "data": {
monsur8643ca82010-02-25 18:45:27 +0000772 "totalPages": 50
monsurf07658c2010-02-22 22:39:56 +0000773 }
774}
775
776</CODE_SNIPPET>
777</BODY>
778</STYLEPOINT>
779</CATEGORY>
780<CATEGORY title="Reserved Property Names for Links">
monsur8643ca82010-02-25 18:45:27 +0000781<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>
monsurf07658c2010-02-22 22:39:56 +0000782<STYLEPOINT title="data.self / data.selfLink">
783<SUMMARY>
784Property Value Type: object / string<br />Parent: <code>data</code>
785</SUMMARY>
786<BODY>
monsur8643ca82010-02-25 18:45:27 +0000787<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>
monsurf07658c2010-02-22 22:39:56 +0000788<CODE_SNIPPET>
789{
790 "data": {
monsur8643ca82010-02-25 18:45:27 +0000791 "self": { },
Ackermann Yuriy79692902016-04-01 21:41:34 +1300792 "selfLink": "https://www.google.com/feeds/album/1234"
monsurf07658c2010-02-22 22:39:56 +0000793 }
794}
795
796</CODE_SNIPPET>
797</BODY>
798</STYLEPOINT>
799<STYLEPOINT title="data.edit / data.editLink">
800<SUMMARY>
801Property Value Type: object / string<br />Parent: <code>data</code>
802</SUMMARY>
803<BODY>
804<p>The edit link indicates where a user can send update or delete requests. This is useful for REST-based APIs. This link need only be present if the user can update/delete this item.</p><p>Example:</p>
805<CODE_SNIPPET>
806{
807 "data": {
monsur8643ca82010-02-25 18:45:27 +0000808 "edit": { },
Ackermann Yuriy79692902016-04-01 21:41:34 +1300809 "editLink": "https://www.google.com/feeds/album/1234/edit"
monsurf07658c2010-02-22 22:39:56 +0000810 }
811}
812
813</CODE_SNIPPET>
814</BODY>
815</STYLEPOINT>
816<STYLEPOINT title="data.next / data.nextLink">
817<SUMMARY>
818Property Value Type: object / string<br />Parent: <code>data</code>
819</SUMMARY>
820<BODY>
monsur8643ca82010-02-25 18:45:27 +0000821<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>
monsurf07658c2010-02-22 22:39:56 +0000822<CODE_SNIPPET>
823{
824 "data": {
monsur8643ca82010-02-25 18:45:27 +0000825 "next": { },
Ackermann Yuriy79692902016-04-01 21:41:34 +1300826 "nextLink": "https://www.google.com/feeds/album/1234/next"
monsurf07658c2010-02-22 22:39:56 +0000827 }
828}
829
830</CODE_SNIPPET>
831</BODY>
832</STYLEPOINT>
833<STYLEPOINT title="data.previous / data.previousLink">
834<SUMMARY>
835Property Value Type: object / string<br />Parent: <code>data</code>
836</SUMMARY>
837<BODY>
monsur8643ca82010-02-25 18:45:27 +0000838<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>
monsurf07658c2010-02-22 22:39:56 +0000839<CODE_SNIPPET>
840{
841 "data": {
monsur8643ca82010-02-25 18:45:27 +0000842 "previous": { },
Ackermann Yuriy79692902016-04-01 21:41:34 +1300843 "previousLink": "https://www.google.com/feeds/album/1234/next"
monsurf07658c2010-02-22 22:39:56 +0000844 }
845}
846
847</CODE_SNIPPET>
848</BODY>
849</STYLEPOINT>
850</CATEGORY>
851<CATEGORY title="Reserved Property Names in the error object">
monsur8643ca82010-02-25 18:45:27 +0000852<p>The <code>error</code> property of the JSON object may contain the following properties.</p>
monsurf07658c2010-02-22 22:39:56 +0000853<STYLEPOINT title="error.code">
854<SUMMARY>
855Property Value Type: integer<br />Parent: <code>error</code>
856</SUMMARY>
857<BODY>
858<p>Represents the code for this error. This property value will usually represent the HTTP response code. If there are multiple errors, <code>code</code> will be the error code for the first error.</p><p>Example:</p>
859<CODE_SNIPPET>
860{
861 "error":{
862 "code": 404
863 }
864}
865
866</CODE_SNIPPET>
867</BODY>
868</STYLEPOINT>
869<STYLEPOINT title="error.message">
870<SUMMARY>
871Property Value Type: string<br />Parent: <code>error</code>
872</SUMMARY>
873<BODY>
874<p>A human readable message providing more details about the error. If there are multiple errors, <code>message</code> will be the message for the first error.</p><p>Example:</p>
875<CODE_SNIPPET>
876{
877 "error":{
878 "message": "File Not Found"
879 }
880}
881
882</CODE_SNIPPET>
883</BODY>
884</STYLEPOINT>
885<STYLEPOINT title="error.errors">
886<SUMMARY>
887Property Value Type: array<br />Parent: <code>error</code>
888</SUMMARY>
889<BODY>
890<p>Container for any additional information regarding the error. If the service returns multiple errors, each element in the <code>errors</code> array represents a different error.</p><p>Example:</p>
891<CODE_SNIPPET>
monsur8643ca82010-02-25 18:45:27 +0000892{ "error": { "errors": [] } }
monsurf07658c2010-02-22 22:39:56 +0000893
894</CODE_SNIPPET>
895</BODY>
896</STYLEPOINT>
897<STYLEPOINT title="error.errors[].domain">
898<SUMMARY>
899Property Value Type: string<br />Parent: <code>error.errors</code>
900</SUMMARY>
901<BODY>
902<p>Unique identifier for the service raising this error. This helps distinguish service-specific errors (i.e. error inserting an event in a calendar) from general protocol errors (i.e. file not found).</p><p>Example:</p>
903<CODE_SNIPPET>
904{
905 "error":{
906 "errors": [{"domain": "Calendar"}]
907 }
908}
909
910</CODE_SNIPPET>
911</BODY>
912</STYLEPOINT>
913<STYLEPOINT title="error.errors[].reason">
914<SUMMARY>
915Property Value Type: string<br />Parent: <code>error.errors</code>
916</SUMMARY>
917<BODY>
918<p>Unique identifier for this error. Different from the <code>error.code</code> property in that this is not an http response code.</p><p>Example:</p>
919<CODE_SNIPPET>
920{
921 "error":{
922 "errors": [{"reason": "ResourceNotFoundException"}]
923 }
924}
925
926</CODE_SNIPPET>
927</BODY>
928</STYLEPOINT>
929<STYLEPOINT title="error.errors[].message">
930<SUMMARY>
931Property Value Type: string<br />Parent: <code>error.errors</code>
932</SUMMARY>
933<BODY>
934<p>A human readable message providing more details about the error. If there is only one error, this field will match <code>error.message</code>.</p><p>Example:</p>
935<CODE_SNIPPET>
936{
937 "error":{
938 "code": 404
939 "message": "File Not Found",
940 "errors": [{"message": "File Not Found"}]
941 }
942}
943
944</CODE_SNIPPET>
945</BODY>
946</STYLEPOINT>
947<STYLEPOINT title="error.errors[].location">
948<SUMMARY>
949Property Value Type: string<br />Parent: <code>error.errors</code>
950</SUMMARY>
951<BODY>
952<p>The location of the error (the interpretation of its value depends on <code>locationType</code>).</p><p>Example:</p>
953<CODE_SNIPPET>
954{
955 "error":{
956 "errors": [{"location": ""}]
957 }
958}
959
960</CODE_SNIPPET>
961</BODY>
962</STYLEPOINT>
963<STYLEPOINT title="error.errors[].locationType">
964<SUMMARY>
965Property Value Type: string<br />Parent: <code>error.errors</code>
966</SUMMARY>
967<BODY>
968<p>Indicates how the <code>location</code> property should be interpreted.</p><p>Example:</p>
969<CODE_SNIPPET>
970{
971 "error":{
972 "errors": [{"locationType": ""}]
973 }
974}
975
976</CODE_SNIPPET>
977</BODY>
978</STYLEPOINT>
979<STYLEPOINT title="error.errors[].extendedHelp">
980<SUMMARY>
981Property Value Type: string<br />Parent: <code>error.errors</code>
982</SUMMARY>
983<BODY>
984<p>A URI for a help text that might shed some more light on the error.</p><p>Example:</p>
985<CODE_SNIPPET>
986{
987 "error":{
988 "errors": [{"extendedHelper": "http://url.to.more.details.example.com/"}]
989 }
990}
991
992</CODE_SNIPPET>
993</BODY>
994</STYLEPOINT>
995<STYLEPOINT title="error.errors[].sendReport">
996<SUMMARY>
997Property Value Type: string<br />Parent: <code>error.errors</code>
998</SUMMARY>
999<BODY>
1000<p>A URI for a report form used by the service to collect data about the error condition. This URI should be preloaded with parameters describing the request.</p><p>Example:</p>
1001<CODE_SNIPPET>
1002{
1003 "error":{
Ackermann Yuriy79692902016-04-01 21:41:34 +13001004 "errors": [{"sendReport": "https://report.example.com/"}]
monsurf07658c2010-02-22 22:39:56 +00001005 }
1006}
1007
1008</CODE_SNIPPET>
1009</BODY>
1010</STYLEPOINT>
1011</CATEGORY>
1012<CATEGORY title="Property Ordering">
1013<p>Properties can be in any order within the JSON object. However, in some cases the ordering of properties can help parsers quickly interpret data and lead to better performance. One example is a pull parser in a mobile environment, where performance and memory are critical, and unnecessary parsing should be avoided.</p>
1014<STYLEPOINT title="Kind Property">
1015<SUMMARY>
1016<code>kind</code> should be the first property
1017</SUMMARY>
1018<BODY>
monsur8643ca82010-02-25 18:45:27 +00001019<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>
monsurf07658c2010-02-22 22:39:56 +00001020</BODY>
1021</STYLEPOINT>
1022<STYLEPOINT title="Items Property">
1023<SUMMARY>
monsur8643ca82010-02-25 18:45:27 +00001024<code>items</code> should be the last property in the <code>data</code> object
monsurf07658c2010-02-22 22:39:56 +00001025</SUMMARY>
1026<BODY>
1027<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>
1028</BODY>
1029</STYLEPOINT>
1030<STYLEPOINT title="Property Ordering Example">
1031<BODY>
1032<CODE_SNIPPET>
1033// The "kind" property distinguishes between an "album" and a "photo".
1034// "Kind" is always the first property in its parent object.
1035// The "items" property is the last property in the "data" object.
1036{
monsur8643ca82010-02-25 18:45:27 +00001037 "data": {
1038 "kind": "album",
1039 "title": "My Photo Album",
1040 "description": "An album in the user's account",
1041 "items": [
monsurf07658c2010-02-22 22:39:56 +00001042 {
monsur8643ca82010-02-25 18:45:27 +00001043 "kind": "photo",
1044 "title": "My First Photo"
monsurf07658c2010-02-22 22:39:56 +00001045 }
1046 ]
1047 }
1048}
1049
1050</CODE_SNIPPET>
1051</BODY>
1052</STYLEPOINT>
1053</CATEGORY>
1054<CATEGORY title="Examples">
1055<STYLEPOINT title="YouTube JSON API">
1056<SUMMARY>
Ackermann Yuriy79692902016-04-01 21:41:34 +13001057Here's an example of the YouTube JSON API's response object. You can learn more about YouTube's JSON API here: <a href="https://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html">https://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html</a>.
monsurf07658c2010-02-22 22:39:56 +00001058</SUMMARY>
1059<BODY>
1060<CODE_SNIPPET>
1061{
1062 "apiVersion": "2.0",
1063 "data": {
1064 "updated": "2010-02-04T19:29:54.001Z",
1065 "totalItems": 6741,
1066 "startIndex": 1,
1067 "itemsPerPage": 1,
1068 "items": [
1069 {
1070 "id": "BGODurRfVv4",
1071 "uploaded": "2009-11-17T20:10:06.000Z",
1072 "updated": "2010-02-04T06:25:57.000Z",
1073 "uploader": "docchat",
1074 "category": "Animals",
1075 "title": "From service dog to SURFice dog",
1076 "description": "Surf dog Ricochets inspirational video ...",
1077 "tags": [
1078 "Surf dog",
1079 "dog surfing",
1080 "dog",
1081 "golden retriever",
1082 ],
1083 "thumbnail": {
Ackermann Yuriy79692902016-04-01 21:41:34 +13001084 "default": "https://i.ytimg.com/vi/BGODurRfVv4/default.jpg",
1085 "hqDefault": "https://i.ytimg.com/vi/BGODurRfVv4/hqdefault.jpg"
monsurf07658c2010-02-22 22:39:56 +00001086 },
1087 "player": {
Ackermann Yuriy79692902016-04-01 21:41:34 +13001088 "default": "https://www.youtube.com/watch?v=BGODurRfVv4&amp;feature=youtube_gdata",
1089 "mobile": "https://m.youtube.com/details?v=BGODurRfVv4"
monsurf07658c2010-02-22 22:39:56 +00001090 },
1091 "content": {
1092 "1": "rtsp://v5.cache6.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
Ackermann Yuriy79692902016-04-01 21:41:34 +13001093 "5": "https://www.youtube.com/v/BGODurRfVv4?f=videos&amp;app=youtube_gdata",
monsurf07658c2010-02-22 22:39:56 +00001094 "6": "rtsp://v7.cache7.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
1095 },
1096 "duration": 315,
1097 "rating": 4.96,
1098 "ratingCount": 2043,
1099 "viewCount": 1781691,
1100 "favoriteCount": 3363,
1101 "commentCount": 1007,
1102 "commentsAllowed": true
1103 }
1104 ]
1105 }
1106}
1107
1108</CODE_SNIPPET>
1109</BODY>
1110</STYLEPOINT>
1111<STYLEPOINT title="Paging Example">
1112<SUMMARY>
1113This example demonstrates how the Google search items could be represented as a JSON object, with special attention to the paging variables.
1114</SUMMARY>
1115<BODY>
1116<p>This sample is for illustrative purposes only. The API below does not actually exist.</p><p>Here's a sample Google search results page:<br /><img src="jsoncstyleguide_example_01.png" /><br /><img src="jsoncstyleguide_example_02.png" /></p><p>Here's a sample JSON representation of this page:</p>
1117<CODE_SNIPPET>
1118{
monsur8643ca82010-02-25 18:45:27 +00001119 "apiVersion": "2.1",
1120 "id": "1",
1121 "data": {
1122 "query": "chicago style pizza",
1123 "time": "0.1",
1124 "currentItemCount": 10,
1125 "itemsPerPage": 10,
1126 "startIndex": 11,
1127 "totalItems": 2700000,
Ackermann Yuriy79692902016-04-01 21:41:34 +13001128 "nextLink": "https://www.google.com/search?hl=en&amp;q=chicago+style+pizza&amp;start=20&amp;sa=N"
1129 "previousLink": "https://www.google.com/search?hl=en&amp;q=chicago+style+pizza&amp;start=0&amp;sa=N",
1130 "pagingLinkTemplate": "https://www.google.com/search/hl=en&amp;q=chicago+style+pizza&amp;start={index}&amp;sa=N",
monsur8643ca82010-02-25 18:45:27 +00001131 "items": [
monsurf07658c2010-02-22 22:39:56 +00001132 {
monsur8643ca82010-02-25 18:45:27 +00001133 "title": "Pizz'a Chicago Home Page"
monsurf07658c2010-02-22 22:39:56 +00001134 // More fields for the search results
1135 }
1136 // More search results
1137 ]
1138 }
1139}
1140
1141</CODE_SNIPPET>
1142<p>Here's how each of the colored boxes from the screenshot would be represented (the background colors correspond to the colors in the images above):</p><ul><li>Results <span style="background-color:rgb(180, 167, 214)">11</span> - 20 of about 2,700,000 = startIndex</li><li>Results 11 - <span style="background-color:rgb(255, 217, 102)">20</span> of about 2,700,000 = startIndex + currentItemCount - 1</li><li>Results 11 - 20 of about <span style="background-color:rgb(246, 178, 107)">2,700,000</span> = totalItems</li><li><span style="background-color:rgb(234, 153, 153)">Search results</span> = items (formatted appropriately)</li><li><span style="background-color:rgb(182, 215, 168)">Previous/Next</span> = previousLink / nextLink</li><li><span style="background-color:rgb(159, 197, 232)">Numbered links in "Gooooooooooogle"</span> = Derived from "pageLinkTemplate". The developer is responsible for calculating the values for {index} and substituting those values into the "pageLinkTemplate". The pageLinkTemplate's {index} variable is calculated as follows:<ul><li>Index #1 = 0 * itemsPerPage = 0</li><li>Index #2 = 2 * itemsPerPage = 10</li><li>Index #3 = 3 * itemsPerPage = 20</li><li>Index #N = N * itemsPerPage</li></ul></li></ul>
1143</BODY>
1144</STYLEPOINT>
1145</CATEGORY>
1146<CATEGORY title="Appendix">
1147<STYLEPOINT title="Appendix A: Reserved JavaScript Words">
1148<SUMMARY>
1149A list of reserved JavaScript words that should be avoided in property names.
1150</SUMMARY>
1151<BODY>
Ackermann Yuriy79692902016-04-01 21:41:34 +13001152<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="https://www.google.com/url?sa=D&amp;q=http%3A%2F%2Fwww.ecma-international.org%2Fpublications%2Fstandards%2FEcma-262.htm">ECMAScript Language Specification 5th Edition</a></p>
monsur8643ca82010-02-25 18:45:27 +00001153<BAD_CODE_SNIPPET>
1154abstract
1155boolean break byte
1156case catch char class const continue
1157debugger default delete do double
1158else enum export extends
1159false final finally float for function
1160goto
1161if implements import in instanceof int interface
1162let long
1163native new null
1164package private protected public
1165return
1166short static super switch synchronized
1167this throw throws transient true try typeof
1168var volatile void
1169while with
monsurf07658c2010-02-22 22:39:56 +00001170yield
monsur8643ca82010-02-25 18:45:27 +00001171</BAD_CODE_SNIPPET>
monsurf07658c2010-02-22 22:39:56 +00001172</BODY>
1173</STYLEPOINT>
1174</CATEGORY>
1175<HR/>
1176
monsur2d29e832010-03-08 18:32:48 +00001177<p align="center">
Ackermann Yuriy79692902016-04-01 21:41:34 +13001178Except as otherwise <a href="https://code.google.com/policies.html">noted</a>, the content of this page is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</a>, and code samples are licensed under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 License</a>.
monsur2d29e832010-03-08 18:32:48 +00001179</p>
monsurf07658c2010-02-22 22:39:56 +00001180<p align="right">
1181Revision 0.9
1182</p>
1183
1184<address>
1185</address>
1186
1187</GUIDE>