I am developing a Google Doc using the Google Docs API, and I came across a JSON ‘dump’ feature that reveals the document structure. However, I’ve noticed that the JSON dump format is not the same as the JSON format utilized for creating or updating the document. For example, I retrieved the following truncated JSON from the dump:
{
"body": {
"content": [
{
"endIndex": 1,
"sectionBreak": {
"sectionStyle": {
"columnSeparatorStyle": "NONE",
"contentDirection": "LEFT_TO_RIGHT"
}
}
},
{
"endIndex": 75,
"paragraph": {
"elements": [
{
"endIndex": 75,
"startIndex": 1,
"textRun": {
"content": "This is a sample paragraph. It represents the initial section of the document.\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"direction": "LEFT_TO_RIGHT",
"namedStyleType": "NORMAL_TEXT"
}
},
"startIndex": 1
}
]
}
}
Meanwhile, this is an example of how the update requests are documented:
const modificationTemplate = {
docId: 'myDocumentID',
data: {
actions: [
{
insertText: {
content: 'hello there',
position: {
index: 1
}
}
}
]
}
};
It appears that while both formats share some common elements, the actual notations for JSON writing differ. I’m looking for a way to format the JSON in a manner that aligns with the ‘dump’ structure, which would make document creation much easier. Otherwise, I would need to manually convert everything between the different formats, which is overwhelming due to the volume of data. Any suggestions or insights would be greatly appreciated!