This Google Apps Script exports data for a selected sheet/a range of selected rows as a JSON string, which can be copied into one .json file. This repository also has a Python program for splitting a huge .json file into individual .json files.
- Either
- Copy-paste the Apps Script in the
.gsin your Apps Script Project; or - Push the script with
clasp- Copy your Apps Script Project's
appsscript.jsonto thesrcfolder.- NOTE: This file is included in the
.gitignorefile so it won't be git-tracked.
- NOTE: This file is included in the
- Configure the
.clasp.jsonfile- Paste your project's Script ID in the
scriptIdattribute. - Note that the path to the actual directory for the Apps Script Project is
Paste this to the
{path_to_the_local_copy_of_your_repo}/export-to-json/srcrootDirattribute.
- Paste your project's Script ID in the
- Run
clasp push- NOTE: Login is required in
clasp.
- NOTE: Login is required in
- Copy your Apps Script Project's
- Copy-paste the Apps Script in the
- Ensure that the Apps Script Project is saved to Google Drive and refresh the spreadsheet you'll use this script with. An
Export JSONmenu should appear on the spreadsheet.
NOTE: You'll have to give some permissions for the Apps Script.
- Select one of the two options in the
Export JSONmenu:Whole Sheet: This exports the selected sheet into a JSON string.Selected Rows: This exports the rows of selected cells in the selected sheet into a JSON string.- This means that you'll only need to select at least one cell in a row for the entire row to be exported as a JSON string.
- Copy the JSON string and paste it into a
.jsonfile. - Download the Python file from the repo (
split.pyin thesrcfolder). - Make a folder in the same folder as the Python file and name it
data. Make a.jsonfile in this folder and paste the JSON string in the file. - Run the Python file and input the file name (without the
.jsonfile extension) you used for the.jsonfile.- If the file name is valid,
.jsonfiles containing individual JSON should appear in thedatafolder. - Just run a formatter (e.g. Prettier) to easily and quickly format the
.jsonfiles.
- If the file name is valid,