[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Use field masks\n\nField masks are a way for API callers to list the fields that a request should\nreturn or update. Using a\n[FieldMask](https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask)\nallows the API to avoid unnecessary work and improves performance. A field mask\nis used for both the read and update methods in the Google Docs API.\n\nRead with a field mask\n----------------------\n\nDocuments can be large, and often you don't need every part of the\n[`Document`](/workspace/docs/api/reference/rest/v1/documents#resource:-document)\nresource returned by a read request. You can limit what's returned in a\nDocs API response, using the `fields` URL parameter. For best\nperformance,\n[explicitly list only the fields you need](/workspace/docs/api/how-tos/performance#partial-response)\nin the reply.\n\nThe format of the fields parameter is the same as the\n[JSON encoding of a FieldMask](https://protobuf.dev/reference/protobuf/google.protobuf/#json-encoding-field-masks).\nStated briefly, multiple different fields are comma-separated and subfields are\ndot-separated. Field names can be specified in **camelCase** or\n**separated_by_underscores**. For convenience, multiple subfields from the same\ntype can be listed within parentheses.\n\nThe following\n[`documents.get`](/workspace/docs/api/reference/rest/v1/documents/get) request\nexample uses a field mask of `title,tabs(documentTab(body.content(paragraph))),revisionId`\nto fetch the document's `title`, the [`Paragraph`](/workspace/docs/api/reference/rest/v1/documents#paragraph)\nof a [`Body`](/workspace/docs/api/reference/rest/v1/documents#body) object (from all\ntabs), and the document's `revisionId` within a document: \n\n```\nGET https://docs.googleapis.com/v1/documents/documentId?fields=title,tabs(documentTab(body.content(paragraph))),revisionId\n```\n\nThe response to this method call is a\n[`Document`](/workspace/docs/api/reference/rest/v1/documents#resource:-document)\nobject containing the components requested in the field mask: \n\n {\n \"title\": \"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\",\n \"revisionId\": \"\u003cvar translate=\"no\"\u003eREVISION_ID\u003c/var\u003e\",\n \"tabs\": [\n {\n \"documentTab\": {\n \"body\": {\n \"content\": [\n {},\n {\n \"paragraph\": {\n \"elements\": [\n {\n \"startIndex\": 1,\n \"endIndex\": 59,\n \"textRun\": {\n \"content\": \"\u003cvar translate=\"no\"\u003eCONTENT\u003c/var\u003e\",\n \"textStyle\": {}\n }\n }\n ],\n \"paragraphStyle\": {\n \"namedStyleType\": \"NORMAL_TEXT\",\n \"direction\": \"LEFT_TO_RIGHT\"\n }\n }\n }\n ]\n }\n }\n }\n ]\n }\n\nUpdate with a field mask\n------------------------\n\nSometimes you need to update only certain fields in an object while leaving the\nother fields unchanged. Update requests inside a\n[`documents.batchUpdate`](/workspace/docs/api/reference/rest/v1/documents/batchUpdate)\noperation use field masks to tell the API which fields are being changed. The\nupdate request ignores any fields that aren't specified in the field mask,\nleaving them with their current values.\n\nYou can also unset a field by not specifying it in the updated message, but\nadding the field to the mask. This clears whatever value the field previously\nhad.\n\nThe syntax for update field masks is the same as read field masks.\n| A field mask of `*` is treated like a wildcard and is shorthand for specifying every field in a message. The wildcard syntax can produce unwanted results if the API is updated in the future, as read-only fields and newly added fields may cause errors. For production applications, always list the specific fields being updated in field masks and avoid using `*` wildcards.\n\nThe following example uses the\n[`UpdateTextStyleRequest`](/workspace/docs/api/reference/rest/v1/documents/request#UpdateTextStyleRequest)\nto style the words \"Google Docs API\" in the document as bold within the `range` 5--20: \n\n```\nPOST https://docs.googleapis.com/v1/documents/documentId:batchUpdate\n``` \n\n {\n \"title\": \"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\",\n \"revisionId\": \"\u003cvar translate=\"no\"\u003eREVISION_ID\u003c/var\u003e\",\n \"suggestionsViewMode\": \"SUGGESTIONS_INLINE\",\n \"documentId\": \"\u003cvar translate=\"no\"\u003eDOCUMENT_ID\u003c/var\u003e\",\n \"tabs\": [\n {\n \"documentTab\": {\n \"body\": {\n \"content\": [\n {\n \"endIndex\": 1,\n \"sectionBreak\": {\n \"sectionStyle\": {\n \"columnSeparatorStyle\": \"NONE\",\n \"contentDirection\": \"LEFT_TO_RIGHT\",\n \"sectionType\": \"CONTINUOUS\"\n }\n }\n },\n {\n \"startIndex\": 1,\n \"endIndex\": 59,\n \"paragraph\": {\n \"elements\": [\n {\n \"startIndex\": 1,\n \"endIndex\": 5,\n \"textRun\": {\n \"content\": \"\u003cvar translate=\"no\"\u003eCONTENT\u003c/var\u003e\",\n \"textStyle\": {}\n }\n },\n {\n \"startIndex\": 5,\n \"endIndex\": 20,\n \"textRun\": {\n \"content\": \"\u003cvar translate=\"no\"\u003eCONTENT\u003c/var\u003e\",\n \"textStyle\": {\n \"bold\": true\n }\n }\n },\n {\n \"startIndex\": 20,\n \"endIndex\": 59,\n \"textRun\": {\n \"content\": \"\u003cvar translate=\"no\"\u003eCONTENT\u003c/var\u003e\",\n \"textStyle\": {}\n }\n }\n ],\n \"paragraphStyle\": {\n \"namedStyleType\": \"NORMAL_TEXT\",\n \"direction\": \"LEFT_TO_RIGHT\"\n }\n }\n }\n ]\n },\n {\n ... // style details\n },\n }\n }\n ],\n }"]]