readability-cli 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1376 @@
1
+ xml-stylesheet type="text/xsl" href="styleguide.xsl"?
2
+
3
+
4
+ # Google JSON Style Guide
5
+
6
+ Revision 0.9
7
+
8
+
9
+
10
+
11
+
12
+ ## Important Note
13
+
14
+ ### Display Hidden Details in this Guide
15
+
16
+ **This 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
+
18
+ Hooray! Now you know you can expand points to get more details. Alternatively, there's an "expand all" at the top of this document.
19
+
20
+
21
+
22
+ ## Introduction
23
+
24
+ This style guide documents guidelines and recommendations for building JSON APIs at Google. In general, JSON APIs should follow the spec found at [JSON.org](https://www.json.org). 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.
25
+
26
+
27
+
28
+ ## Definitions
29
+
30
+ For the purposes of this style guide, we define the following terms:
31
+
32
+ * **property** - a name/value pair inside a JSON object.
33
+ * **property name** - the name (or key) portion of the property.
34
+ * **property value** - the value portion of the property.
35
+
36
+ ```
37
+ {
38
+ // The name/value pair together is a "property".
39
+ "propertyName": "propertyValue"
40
+ }
41
+ ```
42
+
43
+ Javascript's `number` type encompasses all floating-point numbers, which is a broad designation. In this guide, `number` will refer to JavaScript's `number` type, while `integer` will refer to integers.
44
+
45
+
46
+
47
+ ## General Guidelines
48
+
49
+ ### Comments
50
+
51
+ **No comments in JSON objects.**
52
+
53
+ 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.
54
+
55
+ ```
56
+ BAD:
57
+
58
+
59
+ {
60
+ // You may see comments in the examples below,
61
+ // But don't include comments in your JSON.
62
+ "propertyName": "propertyValue"
63
+ }
64
+ ```
65
+
66
+
67
+
68
+ ### Double Quotes
69
+
70
+ **Use double quotes.**
71
+
72
+ 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.
73
+
74
+
75
+
76
+ ### Flattened data vs Structured Hierarchy
77
+
78
+ **Data should not be arbitrarily grouped for convenience.**
79
+
80
+ Data elements should be "flattened" in the JSON representation. Data should not be arbitrarily grouped for convenience.
81
+
82
+ 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:
83
+
84
+ Flattened Address:
85
+
86
+ ```
87
+ {
88
+ "company": "Google",
89
+ "website": "https://www.google.com/",
90
+ "addressLine1": "111 8th Ave",
91
+ "addressLine2": "4th Floor",
92
+ "state": "NY",
93
+ "city": "New York",
94
+ "zip": "10011"
95
+ }
96
+ ```
97
+
98
+ Structured Address:
99
+
100
+ ```
101
+ {
102
+ "company": "Google",
103
+ "website": "https://www.google.com/",
104
+ "address": {
105
+ "line1": "111 8th Ave",
106
+ "line2": "4th Floor",
107
+ "state": "NY",
108
+ "city": "New York",
109
+ "zip": "10011"
110
+ }
111
+ }
112
+ ```
113
+
114
+
115
+
116
+ ## Property Name Guidelines
117
+
118
+ ### Property Name Format
119
+
120
+ **Choose meaningful property names.**
121
+
122
+ Property names must conform to the following guidelines:
123
+
124
+ * Property names should be meaningful names with defined semantics.
125
+ * Property names must be camel-cased, ascii strings.
126
+ * The first character must be a letter, an underscore (\_) or a dollar sign ($).
127
+ * Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.
128
+ * Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).
129
+
130
+ 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:
131
+
132
+ ```
133
+ {
134
+ "thisPropertyIsAnIdentifier": "identifier value"
135
+ }
136
+ ```
137
+
138
+
139
+
140
+ ### Key Names in JSON Maps
141
+
142
+ **JSON maps can use any Unicode character in key names.**
143
+
144
+ 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.
145
+
146
+ 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"]`).
147
+
148
+ ```
149
+ {
150
+ // The "address" property is a sub-object
151
+ // holding the parts of an address.
152
+ "address": {
153
+ "addressLine1": "123 Anystreet",
154
+ "city": "Anytown",
155
+ "state": "XX",
156
+ "zip": "00000"
157
+ },
158
+ // The "thumbnails" property is a map that maps
159
+ // a pixel size to the thumbnail url of that size.
160
+ "thumbnails": {
161
+ "72": "https://url.to.72px.thumbnail",
162
+ "144": "https://url.to.144px.thumbnail"
163
+ }
164
+ }
165
+ ```
166
+
167
+
168
+
169
+ ### Reserved Property Names
170
+
171
+ **Certain property names are reserved for consistent use across services.**
172
+
173
+ 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.
174
+
175
+
176
+
177
+ ### Singular vs Plural Property Names
178
+
179
+ **Array types should have plural property names. All other property names should be singular.**
180
+
181
+ 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.
182
+
183
+ 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.
184
+
185
+ ```
186
+ {
187
+ // Singular
188
+ "author": "lisa",
189
+ // An array of siblings, plural
190
+ "siblings": [ "bart", "maggie"],
191
+ // "totalItem" doesn't sound right
192
+ "totalItems": 10,
193
+ // But maybe "itemCount" is better
194
+ "itemCount": 10,
195
+ }
196
+ ```
197
+
198
+
199
+
200
+ ### Naming Conflicts
201
+
202
+ **Avoid naming conflicts by choosing a new property name or versioning the API.**
203
+
204
+ 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:
205
+
206
+ ```
207
+ {
208
+ "apiVersion": "1.0",
209
+ "data": {
210
+ "recipeName": "pizza",
211
+ "ingredients": ["tomatoes", "cheese", "sausage"]
212
+ }
213
+ }
214
+ ```
215
+
216
+ If in the future we wish to make `ingredients` a reserved word, we can do one of two things:
217
+
218
+ 1) Choose a different name:
219
+
220
+ ```
221
+ {
222
+ "apiVersion": "1.0",
223
+ "data": {
224
+ "recipeName": "pizza",
225
+ "ingredientsData": "Some new property",
226
+ "ingredients": ["tomatoes", "cheese", "sausage"]
227
+ }
228
+ }
229
+ ```
230
+
231
+ 2) Rename the property on a major version boundary:
232
+
233
+ ```
234
+ {
235
+ "apiVersion": "2.0",
236
+ "data": {
237
+ "recipeName": "pizza",
238
+ "ingredients": "Some new property",
239
+ "recipeIngredients": ["tomatos", "cheese", "sausage"]
240
+ }
241
+ }
242
+ ```
243
+
244
+
245
+
246
+ ## Property Value Guidelines
247
+
248
+ ### Property Value Format
249
+
250
+ **Property values must be booleans, numbers, Unicode strings, objects, arrays, or `null`.**
251
+
252
+ The spec at [JSON.org](https://www.json.org) specifies exactly what type of data is allowed in a property value. This includes booleans, numbers, Unicode strings, objects, arrays, and `null`. 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.).
253
+
254
+ Good:
255
+
256
+ ```
257
+ {
258
+ "canPigsFly": null, // null
259
+ "areWeThereYet": false, // boolean
260
+ "answerToLife": 42, // number
261
+ "name": "Bart", // string
262
+ "moreData": {}, // object
263
+ "things": [] // array
264
+ }
265
+ ```
266
+
267
+ Bad:
268
+
269
+ ```
270
+ BAD:
271
+
272
+
273
+ {
274
+ "aVariableName": aVariableName, // Bad - JavaScript identifier
275
+ "functionFoo": function() { return 1; } // Bad - JavaScript function
276
+ }
277
+ ```
278
+
279
+
280
+
281
+ ### Empty/Null Property Values
282
+
283
+ **Consider removing empty or `null` values.**
284
+
285
+ If a property is optional or has an empty or `null` value, consider dropping the property from the JSON, unless there's a strong semantic reason for its existence.
286
+
287
+ ```
288
+ {
289
+ "volume": 10,
290
+
291
+ // Even though the "balance" property's value is zero, it should be left in,
292
+ // since "0" signifies "even balance" (the value could be "-1" for left
293
+ // balance and "+1" for right balance.
294
+ "balance": 0,
295
+
296
+ // The "currentlyPlaying" property can be left out since it is null.
297
+ // "currentlyPlaying": null
298
+ }
299
+ ```
300
+
301
+
302
+
303
+ ### Enum Values
304
+
305
+ **Enum values should be represented as strings.**
306
+
307
+ 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.
308
+
309
+ Java code:
310
+
311
+ ```
312
+ public enum Color {
313
+ WHITE,
314
+ BLACK,
315
+ RED,
316
+ YELLOW,
317
+ BLUE
318
+ }
319
+ ```
320
+
321
+ JSON object:
322
+
323
+ ```
324
+ {
325
+ "color": "WHITE"
326
+ }
327
+ ```
328
+
329
+
330
+
331
+ ## Property Value Data Types
332
+
333
+ As mentioned above, property value types must be booleans, numbers, strings, objects, arrays, or `null`. 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.
334
+
335
+ ### Date Property Values
336
+
337
+ **Dates should be formatted as recommended by RFC 3339.**
338
+
339
+ Dates should be strings formatted as recommended by [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt)
340
+
341
+ ```
342
+ {
343
+ "lastUpdate": "2007-11-06T16:34:41.000Z"
344
+ }
345
+ ```
346
+
347
+
348
+
349
+ ### Time Duration Property Values
350
+
351
+ **Time durations should be formatted as recommended by ISO 8601.**
352
+
353
+ Time duration values should be strings formatted as recommended by [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations).
354
+
355
+ ```
356
+ {
357
+ // three years, six months, four days, twelve hours,
358
+ // thirty minutes, and five seconds
359
+ "duration": "P3Y6M4DT12H30M5S"
360
+ }
361
+ ```
362
+
363
+
364
+
365
+ ### Latitude/Longitude Property Values
366
+
367
+ **Latitudes/Longitudes should be formatted as recommended by ISO 6709.**
368
+
369
+ Latitude/Longitude should be strings formatted as recommended by [ISO 6709](https://en.wikipedia.org/wiki/ISO_6709). Furthermore, they should favor the ±DD.DDDD±DDD.DDDD degrees format.
370
+
371
+ ```
372
+ {
373
+ // The latitude/longitude location of the statue of liberty.
374
+ "statueOfLiberty": "+40.6894-074.0447"
375
+ }
376
+ ```
377
+
378
+
379
+
380
+ ## JSON Structure & Reserved Property Names
381
+
382
+ 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 recommended. Here is a schema of the JSON structure, represented in [Orderly](https://www.google.com/url?sa=D&q=http%3A%2F%2Forderly-json.org%2F) format (which in turn can be compiled into a [JSONSchema](https://www.google.com/url?sa=D&q=http%3A%2F%2Fjson-schema.org%2F)). You can few examples of the JSON structure at the end of this guide.
383
+
384
+ ```
385
+ object {
386
+ string apiVersion?;
387
+ string context?;
388
+ string id?;
389
+ string method?;
390
+ object {
391
+ string id?
392
+ }* params?;
393
+ object {
394
+ string kind?;
395
+ string fields?;
396
+ string etag?;
397
+ string id?;
398
+ string lang?;
399
+ string updated?; # date formatted RFC 3339
400
+ boolean deleted?;
401
+ integer currentItemCount?;
402
+ integer itemsPerPage?;
403
+ integer startIndex?;
404
+ integer totalItems?;
405
+ integer pageIndex?;
406
+ integer totalPages?;
407
+ string pageLinkTemplate /^https?:/ ?;
408
+ object {}* next?;
409
+ string nextLink?;
410
+ object {}* previous?;
411
+ string previousLink?;
412
+ object {}* self?;
413
+ string selfLink?;
414
+ object {}* edit?;
415
+ string editLink?;
416
+ array [
417
+ object {}*;
418
+ ] items?;
419
+ }* data?;
420
+ object {
421
+ integer code?;
422
+ string message?;
423
+ array [
424
+ object {
425
+ string domain?;
426
+ string reason?;
427
+ string message?;
428
+ string location?;
429
+ string locationType?;
430
+ string extendedHelp?;
431
+ string sendReport?;
432
+ }*;
433
+ ] errors?;
434
+ }* error?;
435
+ }*;
436
+ ```
437
+
438
+ The JSON object has a few top-level properties, followed by either a `data` object or an `error` object, but not both. An explanation of each of these properties can be found below.
439
+
440
+
441
+
442
+ ## Top-Level Reserved Property Names
443
+
444
+ The top-level of the JSON object may contain the following properties.
445
+
446
+ ### apiVersion
447
+
448
+ **Property Value Type: string
449
+ Parent: -**
450
+
451
+ 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.
452
+
453
+ Example:
454
+
455
+ ```
456
+ { "apiVersion": "2.1" }
457
+ ```
458
+
459
+
460
+
461
+ ### context
462
+
463
+ **Property Value Type: string
464
+ Parent: -**
465
+
466
+ 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.
467
+
468
+ Example:
469
+
470
+ Request #1:
471
+
472
+ ```
473
+ https://www.google.com/myapi?context=bart
474
+ ```
475
+
476
+ Request #2:
477
+
478
+ ```
479
+ https://www.google.com/myapi?context=lisa
480
+ ```
481
+
482
+ Response #1:
483
+
484
+ ```
485
+ {
486
+ "context": "bart",
487
+ "data": {
488
+ "items": []
489
+ }
490
+ }
491
+ ```
492
+
493
+ Response #2:
494
+
495
+ ```
496
+ {
497
+ "context": "lisa",
498
+ "data": {
499
+ "items": []
500
+ }
501
+ }
502
+ ```
503
+
504
+ Common JavaScript handler code to process both responses:
505
+
506
+ ```
507
+ function handleResponse(response) {
508
+ if (response.result.context == "bart") {
509
+ // Update the "Bart" section of the page.
510
+ } else if (response.result.context == "lisa") {
511
+ // Update the "Lisa" section of the page.
512
+ }
513
+ }
514
+ ```
515
+
516
+
517
+
518
+ ### id
519
+
520
+ **Property Value Type: string
521
+ Parent: -**
522
+
523
+ 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.
524
+
525
+ Example:
526
+
527
+ ```
528
+ { "id": "1" }
529
+ ```
530
+
531
+
532
+
533
+ ### method
534
+
535
+ **Property Value Type: string
536
+ Parent: -**
537
+
538
+ 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.
539
+
540
+ One example of this is in JSON-RPC requests, where `method` indicates the operation to perform on the `params` property:
541
+
542
+ ```
543
+ {
544
+ "method": "people.get",
545
+ "params": {
546
+ "userId": "@me",
547
+ "groupId": "@self"
548
+ }
549
+ }
550
+ ```
551
+
552
+
553
+
554
+ ### params
555
+
556
+ **Property Value Type: object
557
+ Parent: -**
558
+
559
+ 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.
560
+
561
+ Example:
562
+
563
+ ```
564
+ {
565
+ "method": "people.get",
566
+ "params": {
567
+ "userId": "@me",
568
+ "groupId": "@self"
569
+ }
570
+ }
571
+ ```
572
+
573
+
574
+
575
+ ### data
576
+
577
+ **Property Value Type: object
578
+ Parent: -**
579
+
580
+ 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.
581
+
582
+
583
+
584
+ ### error
585
+
586
+ **Property Value Type: object
587
+ Parent: -**
588
+
589
+ 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.
590
+
591
+ Example:
592
+
593
+ ```
594
+ {
595
+ "apiVersion": "2.0",
596
+ "error": {
597
+ "code": 404,
598
+ "message": "File Not Found",
599
+ "errors": [{
600
+ "domain": "Calendar",
601
+ "reason": "ResourceNotFoundException",
602
+ "message": "File Not Found"
603
+ }]
604
+ }
605
+ }
606
+ ```
607
+
608
+
609
+
610
+ ## Reserved Property Names in the data object
611
+
612
+ The `data` property of the JSON object may contain the following properties.
613
+
614
+ ### data.kind
615
+
616
+ **Property Value Type: string
617
+ Parent: `data`**
618
+
619
+ 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).
620
+
621
+ Example:
622
+
623
+ ```
624
+ // "Kind" indicates an "album" in the Picasa API.
625
+ {"data": {"kind": "album"}}
626
+ ```
627
+
628
+
629
+
630
+ ### data.fields
631
+
632
+ **Property Value Type: string
633
+ Parent: `data`**
634
+
635
+ 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.
636
+
637
+ Example:
638
+
639
+ ```
640
+ {
641
+ "data": {
642
+ "kind": "user",
643
+ "fields": "author,id",
644
+ "id": "bart",
645
+ "author": "Bart"
646
+ }
647
+ }
648
+ ```
649
+
650
+
651
+
652
+ ### data.etag
653
+
654
+ **Property Value Type: string
655
+ Parent: `data`**
656
+
657
+ Represents the etag for the response. Details about ETags in the GData APIs can be found here: <https://code.google.com/apis/gdata/docs/2.0/reference.html#ResourceVersioning>
658
+
659
+ Example:
660
+
661
+ ```
662
+ {"data": {"etag": "W/"C0QBRXcycSp7ImA9WxRVFUk.""}}
663
+ ```
664
+
665
+
666
+
667
+ ### data.id
668
+
669
+ **Property Value Type: string
670
+ Parent: `data`**
671
+
672
+ A globally unique string used to reference the object. The specific details of the `id` property are left up to the service.
673
+
674
+ Example:
675
+
676
+ ```
677
+ {"data": {"id": "12345"}}
678
+ ```
679
+
680
+
681
+
682
+ ### data.lang
683
+
684
+ **Property Value Type: string (formatted as specified in BCP 47)
685
+ Parent: `data (or any child element)`**
686
+
687
+ Indicates the language of the rest of the properties in this object. This property mimics HTML's `lang` property and XML's `xml:lang` properties. The value should be a language value as defined in [BCP 47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt). If a single JSON object contains data in multiple languages, the service is responsible for developing and documenting an appropriate location for the `lang` property.
688
+
689
+ Example:
690
+
691
+ ```
692
+ {"data": {
693
+ "items": [
694
+ { "lang": "en",
695
+ "title": "Hello world!" },
696
+ { "lang": "fr",
697
+ "title": "Bonjour monde!" }
698
+ ]}
699
+ }
700
+ ```
701
+
702
+
703
+
704
+ ### data.updated
705
+
706
+ **Property Value Type: string (formatted as specified in RFC 3339)
707
+ Parent: `data`**
708
+
709
+ Indicates the last date/time ([RFC 3339](https://www.ietf.org/rfc/rfc3339.txt)) the item was updated, as defined by the service.
710
+
711
+ Example:
712
+
713
+ ```
714
+ {"data": {"updated": "2007-11-06T16:34:41.000Z"}}
715
+ ```
716
+
717
+
718
+
719
+ ### data.deleted
720
+
721
+ **Property Value Type: boolean
722
+ Parent: `data (or any child element)`**
723
+
724
+ A marker element, that, when present, indicates the containing entry is deleted. If deleted is present, its value must be `true`; a value of `false` can cause confusion and should be avoided.
725
+
726
+ Example:
727
+
728
+ ```
729
+ {"data": {
730
+ "items": [
731
+ { "title": "A deleted entry",
732
+ "deleted": true
733
+ }
734
+ ]}
735
+ }
736
+ ```
737
+
738
+
739
+
740
+ ### data.items
741
+
742
+ **Property Value Type: array
743
+ Parent: `data`**
744
+
745
+ 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).
746
+
747
+ Example:
748
+
749
+ ```
750
+ {
751
+ "data": {
752
+ "items": [
753
+ { /* Object #1 */ },
754
+ { /* Object #2 */ },
755
+ ...
756
+ ]
757
+ }
758
+ }
759
+ ```
760
+
761
+
762
+
763
+ ## Reserved Property Names for Paging
764
+
765
+ The following properties are located in the `data` object, and help page through a list of items. Some of the language and concepts are borrowed from the [OpenSearch specification](https://www.opensearch.org/).
766
+
767
+ The paging properties below allow for various styles of paging, including:
768
+
769
+ * Previous/Next paging - Allows user's to move forward and backward through a list, one page at a time. The `nextLink` and `previousLink` properties (described in the "Reserved Property Names for Links" section below) are used for this style of paging.
770
+ * 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 `?startIndex=200`.
771
+ * 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 `?page=1` or `?page=20`. The `pageIndex` and `totalPages` properties are used for this style of paging.
772
+
773
+ An example of how to use these properties to implement paging can be found at the end of this guide.
774
+
775
+ ### data.currentItemCount
776
+
777
+ **Property Value Type: integer
778
+ Parent: `data`**
779
+
780
+ 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 `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".
781
+
782
+ Example:
783
+
784
+ ```
785
+ {
786
+ "data": {
787
+ // "itemsPerPage" does not necessarily match "currentItemCount"
788
+ "itemsPerPage": 10,
789
+ "currentItemCount": 4
790
+ }
791
+ }
792
+ ```
793
+
794
+
795
+
796
+ ### data.itemsPerPage
797
+
798
+ **Property Value Type: integer
799
+ Parent: `data`**
800
+
801
+ 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`.
802
+
803
+ Example:
804
+
805
+ ```
806
+ {
807
+ "data": {
808
+ "itemsPerPage": 10
809
+ }
810
+ }
811
+ ```
812
+
813
+
814
+
815
+ ### data.startIndex
816
+
817
+ **Property Value Type: integer
818
+ Parent: `data`**
819
+
820
+ 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.
821
+
822
+ Example:
823
+
824
+ ```
825
+ {
826
+ "data": {
827
+ "startIndex": 1
828
+ }
829
+ }
830
+ ```
831
+
832
+
833
+
834
+ ### data.totalItems
835
+
836
+ **Property Value Type: integer
837
+ Parent: `data`**
838
+
839
+ 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.
840
+
841
+ Example:
842
+
843
+ ```
844
+ {
845
+ "data": {
846
+ "totalItems": 100
847
+ }
848
+ }
849
+ ```
850
+
851
+
852
+
853
+ ### data.pagingLinkTemplate
854
+
855
+ **Property Value Type: string
856
+ Parent: `data`**
857
+
858
+ 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.
859
+
860
+ Example:
861
+
862
+ ```
863
+ {
864
+ "data": {
865
+ "pagingLinkTemplate": "https://www.google.com/search/hl=en&q=chicago+style+pizza&start={index}&sa=N"
866
+ }
867
+ }
868
+ ```
869
+
870
+
871
+
872
+ ### data.pageIndex
873
+
874
+ **Property Value Type: integer
875
+ Parent: `data`**
876
+
877
+ 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`.
878
+
879
+ Example:
880
+
881
+ ```
882
+ {
883
+ "data": {
884
+ "pageIndex": 1
885
+ }
886
+ }
887
+ ```
888
+
889
+
890
+
891
+ ### data.totalPages
892
+
893
+ **Property Value Type: integer
894
+ Parent: `data`**
895
+
896
+ 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)`.
897
+
898
+ Example:
899
+
900
+ ```
901
+ {
902
+ "data": {
903
+ "totalPages": 50
904
+ }
905
+ }
906
+ ```
907
+
908
+
909
+
910
+ ## Reserved Property Names for Links
911
+
912
+ 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").
913
+
914
+ ### data.self / data.selfLink
915
+
916
+ **Property Value Type: object / string
917
+ Parent: `data`**
918
+
919
+ 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.
920
+
921
+ Example:
922
+
923
+ ```
924
+ {
925
+ "data": {
926
+ "self": { },
927
+ "selfLink": "https://www.google.com/feeds/album/1234"
928
+ }
929
+ }
930
+ ```
931
+
932
+
933
+
934
+ ### data.edit / data.editLink
935
+
936
+ **Property Value Type: object / string
937
+ Parent: `data`**
938
+
939
+ 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.
940
+
941
+ Example:
942
+
943
+ ```
944
+ {
945
+ "data": {
946
+ "edit": { },
947
+ "editLink": "https://www.google.com/feeds/album/1234/edit"
948
+ }
949
+ }
950
+ ```
951
+
952
+
953
+
954
+ ### data.next / data.nextLink
955
+
956
+ **Property Value Type: object / string
957
+ Parent: `data`**
958
+
959
+ 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.
960
+
961
+ Example:
962
+
963
+ ```
964
+ {
965
+ "data": {
966
+ "next": { },
967
+ "nextLink": "https://www.google.com/feeds/album/1234/next"
968
+ }
969
+ }
970
+ ```
971
+
972
+
973
+
974
+ ### data.previous / data.previousLink
975
+
976
+ **Property Value Type: object / string
977
+ Parent: `data`**
978
+
979
+ 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.
980
+
981
+ Example:
982
+
983
+ ```
984
+ {
985
+ "data": {
986
+ "previous": { },
987
+ "previousLink": "https://www.google.com/feeds/album/1234/next"
988
+ }
989
+ }
990
+ ```
991
+
992
+
993
+
994
+ ## Reserved Property Names in the error object
995
+
996
+ The `error` property of the JSON object may contain the following properties.
997
+
998
+ ### error.code
999
+
1000
+ **Property Value Type: integer
1001
+ Parent: `error`**
1002
+
1003
+ Represents the code for this error. This property value will usually represent the HTTP response code. If there are multiple errors, `code` will be the error code for the first error.
1004
+
1005
+ Example:
1006
+
1007
+ ```
1008
+ {
1009
+ "error":{
1010
+ "code": 404
1011
+ }
1012
+ }
1013
+ ```
1014
+
1015
+
1016
+
1017
+ ### error.message
1018
+
1019
+ **Property Value Type: string
1020
+ Parent: `error`**
1021
+
1022
+ A human readable message providing more details about the error. If there are multiple errors, `message` will be the message for the first error.
1023
+
1024
+ Example:
1025
+
1026
+ ```
1027
+ {
1028
+ "error":{
1029
+ "message": "File Not Found"
1030
+ }
1031
+ }
1032
+ ```
1033
+
1034
+
1035
+
1036
+ ### error.errors
1037
+
1038
+ **Property Value Type: array
1039
+ Parent: `error`**
1040
+
1041
+ Container for any additional information regarding the error. If the service returns multiple errors, each element in the `errors` array represents a different error.
1042
+
1043
+ Example:
1044
+
1045
+ ```
1046
+ { "error": { "errors": [] } }
1047
+ ```
1048
+
1049
+
1050
+
1051
+ ### error.errors[].domain
1052
+
1053
+ **Property Value Type: string
1054
+ Parent: `error.errors`**
1055
+
1056
+ 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).
1057
+
1058
+ Example:
1059
+
1060
+ ```
1061
+ {
1062
+ "error":{
1063
+ "errors": [{"domain": "Calendar"}]
1064
+ }
1065
+ }
1066
+ ```
1067
+
1068
+
1069
+
1070
+ ### error.errors[].reason
1071
+
1072
+ **Property Value Type: string
1073
+ Parent: `error.errors`**
1074
+
1075
+ Unique identifier for this error. Different from the `error.code` property in that this is not an http response code.
1076
+
1077
+ Example:
1078
+
1079
+ ```
1080
+ {
1081
+ "error":{
1082
+ "errors": [{"reason": "ResourceNotFoundException"}]
1083
+ }
1084
+ }
1085
+ ```
1086
+
1087
+
1088
+
1089
+ ### error.errors[].message
1090
+
1091
+ **Property Value Type: string
1092
+ Parent: `error.errors`**
1093
+
1094
+ A human readable message providing more details about the error. If there is only one error, this field will match `error.message`.
1095
+
1096
+ Example:
1097
+
1098
+ ```
1099
+ {
1100
+ "error":{
1101
+ "code": 404,
1102
+ "message": "File Not Found",
1103
+ "errors": [{"message": "File Not Found"}]
1104
+ }
1105
+ }
1106
+ ```
1107
+
1108
+
1109
+
1110
+ ### error.errors[].location
1111
+
1112
+ **Property Value Type: string
1113
+ Parent: `error.errors`**
1114
+
1115
+ The location of the error (the interpretation of its value depends on `locationType`).
1116
+
1117
+ Example:
1118
+
1119
+ ```
1120
+ {
1121
+ "error":{
1122
+ "errors": [{"location": ""}]
1123
+ }
1124
+ }
1125
+ ```
1126
+
1127
+
1128
+
1129
+ ### error.errors[].locationType
1130
+
1131
+ **Property Value Type: string
1132
+ Parent: `error.errors`**
1133
+
1134
+ Indicates how the `location` property should be interpreted.
1135
+
1136
+ Example:
1137
+
1138
+ ```
1139
+ {
1140
+ "error":{
1141
+ "errors": [{"locationType": ""}]
1142
+ }
1143
+ }
1144
+ ```
1145
+
1146
+
1147
+
1148
+ ### error.errors[].extendedHelp
1149
+
1150
+ **Property Value Type: string
1151
+ Parent: `error.errors`**
1152
+
1153
+ A URI for a help text that might shed some more light on the error.
1154
+
1155
+ Example:
1156
+
1157
+ ```
1158
+ {
1159
+ "error":{
1160
+ "errors": [{"extendedHelper": "https://url.to.more.details.example.com/"}]
1161
+ }
1162
+ }
1163
+ ```
1164
+
1165
+
1166
+
1167
+ ### error.errors[].sendReport
1168
+
1169
+ **Property Value Type: string
1170
+ Parent: `error.errors`**
1171
+
1172
+ 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.
1173
+
1174
+ Example:
1175
+
1176
+ ```
1177
+ {
1178
+ "error":{
1179
+ "errors": [{"sendReport": "https://report.example.com/"}]
1180
+ }
1181
+ }
1182
+ ```
1183
+
1184
+
1185
+
1186
+ ## Property Ordering
1187
+
1188
+ 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.
1189
+
1190
+ ### Kind Property
1191
+
1192
+ **`kind` should be the first property**
1193
+
1194
+ 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).
1195
+
1196
+
1197
+
1198
+ ### Items Property
1199
+
1200
+ **`items` should be the last property in the `data` object**
1201
+
1202
+ 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.
1203
+
1204
+
1205
+
1206
+ ### Property Ordering Example
1207
+
1208
+ ```
1209
+ // The "kind" property distinguishes between an "album" and a "photo".
1210
+ // "Kind" is always the first property in its parent object.
1211
+ // The "items" property is the last property in the "data" object.
1212
+ {
1213
+ "data": {
1214
+ "kind": "album",
1215
+ "title": "My Photo Album",
1216
+ "description": "An album in the user's account",
1217
+ "items": [
1218
+ {
1219
+ "kind": "photo",
1220
+ "title": "My First Photo"
1221
+ }
1222
+ ]
1223
+ }
1224
+ }
1225
+ ```
1226
+
1227
+
1228
+
1229
+ ## Examples
1230
+
1231
+ ### YouTube JSON API
1232
+
1233
+ **Here's an example of the YouTube JSON API's response object. You can learn more about YouTube's JSON API here: <https://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html>.**
1234
+
1235
+ ```
1236
+ {
1237
+ "apiVersion": "2.0",
1238
+ "data": {
1239
+ "updated": "2010-02-04T19:29:54.001Z",
1240
+ "totalItems": 6741,
1241
+ "startIndex": 1,
1242
+ "itemsPerPage": 1,
1243
+ "items": [
1244
+ {
1245
+ "id": "BGODurRfVv4",
1246
+ "uploaded": "2009-11-17T20:10:06.000Z",
1247
+ "updated": "2010-02-04T06:25:57.000Z",
1248
+ "uploader": "docchat",
1249
+ "category": "Animals",
1250
+ "title": "From service dog to SURFice dog",
1251
+ "description": "Surf dog Ricochets inspirational video ...",
1252
+ "tags": [
1253
+ "Surf dog",
1254
+ "dog surfing",
1255
+ "dog",
1256
+ "golden retriever",
1257
+ ],
1258
+ "thumbnail": {
1259
+ "default": "https://i.ytimg.com/vi/BGODurRfVv4/default.jpg",
1260
+ "hqDefault": "https://i.ytimg.com/vi/BGODurRfVv4/hqdefault.jpg"
1261
+ },
1262
+ "player": {
1263
+ "default": "https://www.youtube.com/watch?v=BGODurRfVv4&feature=youtube_gdata",
1264
+ "mobile": "https://m.youtube.com/details?v=BGODurRfVv4"
1265
+ },
1266
+ "content": {
1267
+ "1": "rtsp://v5.cache6.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
1268
+ "5": "https://www.youtube.com/v/BGODurRfVv4?f=videos&app=youtube_gdata",
1269
+ "6": "rtsp://v7.cache7.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"
1270
+ },
1271
+ "duration": 315,
1272
+ "rating": 4.96,
1273
+ "ratingCount": 2043,
1274
+ "viewCount": 1781691,
1275
+ "favoriteCount": 3363,
1276
+ "commentCount": 1007,
1277
+ "commentsAllowed": true
1278
+ }
1279
+ ]
1280
+ }
1281
+ }
1282
+ ```
1283
+
1284
+
1285
+
1286
+ ### Paging Example
1287
+
1288
+ **This example demonstrates how the Google search items could be represented as a JSON object, with special attention to the paging variables.**
1289
+
1290
+ This sample is for illustrative purposes only. The API below does not actually exist.
1291
+
1292
+ Here's a sample Google search results page:
1293
+ ![](jsoncstyleguide_example_01.png)
1294
+ ![](jsoncstyleguide_example_02.png)
1295
+
1296
+ Here's a sample JSON representation of this page:
1297
+
1298
+ ```
1299
+ {
1300
+ "apiVersion": "2.1",
1301
+ "id": "1",
1302
+ "data": {
1303
+ "query": "chicago style pizza",
1304
+ "time": "0.1",
1305
+ "currentItemCount": 10,
1306
+ "itemsPerPage": 10,
1307
+ "startIndex": 11,
1308
+ "totalItems": 2700000,
1309
+ "nextLink": "https://www.google.com/search?hl=en&q=chicago+style+pizza&start=20&sa=N"
1310
+ "previousLink": "https://www.google.com/search?hl=en&q=chicago+style+pizza&start=0&sa=N",
1311
+ "pagingLinkTemplate": "https://www.google.com/search/hl=en&q=chicago+style+pizza&start={index}&sa=N",
1312
+ "items": [
1313
+ {
1314
+ "title": "Pizz'a Chicago Home Page"
1315
+ // More fields for the search results
1316
+ }
1317
+ // More search results
1318
+ ]
1319
+ }
1320
+ }
1321
+ ```
1322
+
1323
+ 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):
1324
+
1325
+ * Results 11 - 20 of about 2,700,000 = startIndex
1326
+ * Results 11 - 20 of about 2,700,000 = startIndex + currentItemCount - 1
1327
+ * Results 11 - 20 of about 2,700,000 = totalItems
1328
+ * Search results = items (formatted appropriately)
1329
+ * Previous/Next = previousLink / nextLink
1330
+ * Numbered links in "Gooooooooooogle" = 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:
1331
+ + Index #1 = 0 \* itemsPerPage = 0
1332
+ + Index #2 = 2 \* itemsPerPage = 10
1333
+ + Index #3 = 3 \* itemsPerPage = 20
1334
+ + Index #N = N \* itemsPerPage
1335
+
1336
+
1337
+ ## Appendix
1338
+
1339
+ ### Appendix A: Reserved JavaScript Words
1340
+
1341
+ **A list of reserved JavaScript words that should be avoided in property names.**
1342
+
1343
+ 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.
1344
+
1345
+ From the [ECMAScript Language Specification 5th Edition](https://www.google.com/url?sa=D&q=http%3A%2F%2Fwww.ecma-international.org%2Fpublications%2Fstandards%2FEcma-262.htm)
1346
+
1347
+ ```
1348
+ BAD:
1349
+
1350
+
1351
+ abstract
1352
+ boolean break byte
1353
+ case catch char class const continue
1354
+ debugger default delete do double
1355
+ else enum export extends
1356
+ false final finally float for function
1357
+ goto
1358
+ if implements import in instanceof int interface
1359
+ let long
1360
+ native new null
1361
+ package private protected public
1362
+ return
1363
+ short static super switch synchronized
1364
+ this throw throws transient true try typeof
1365
+ var volatile void
1366
+ while with
1367
+ yield
1368
+ ```
1369
+
1370
+
1371
+
1372
+ ---
1373
+
1374
+ Except as otherwise [noted](https://code.google.com/policies.html), the content of this page is licensed under the [Creative Commons Attribution 3.0 License](https://creativecommons.org/licenses/by/3.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
1375
+
1376
+ Revision 0.9