Question: I could not find the solution to this error in the previous answers. I'm running this script under Google Apps Scripts with Google Sheets. So I would like you to review my simple line of code to see if there is something I overlooked:

`var firstCSV = SpreadsheetApp.openByUrl("https://drive.google.com/file/d/14EA51XsRpohpFVCwpO3sZwf_H3o6Dp_o/edit#gid=0");`

Error on this line -

`Exception: Service Spreadsheets failed while accessing document with id 14EA51XsRpohpFVCwpO3sZwf_H3o6Dp_o. GregReport @ Receipts Calculator.gs:37`

* I first tried using "openById" using just the ID number and got the
same error message.
* Next I tried using the "openByUrl" using the document's URL and got  

the same error message.
* I checked the file on Google drive and it's there and I can open it.
* I ran this line of code in a script by itself and got the same error.
* I changed the URL in the code to a Sheets document URL an I got the  

same error.
* The original file has a .csv extension but my understanding is this  

should work just fine in Sheets.
* With both document formats and different methods I'm getting this  

same error.
* Any suggestions, or code updates I'm not aware would be appreciated.
All I'm trying to do is open a spreadsheet and extract some data from
it using a script built in Sheets.

Answer: 
Here is the working code

```js
import { config } from 'https://deno.land/x/dotenv/mod.ts';
import { writeJson } from 'https://deno.land/x/jsonfile/mod.ts';

// replace with correct type
type PackageJson = object

config({ export: true, safe: true });

async function writePackageJsonFile(filename: string, contents: PackageJson) {
  await writeJson(filename, contents, { spaces: 2 });
}

const packageName: string = Deno.env.get('PACKAGE_NAME')!;
const content: string = Deno.env.get('PACKAGE_CONTENTS')!;

const parsedContent: PackageJson = JSON.parse(content);
await writePackageJsonFile(packageName, parsedContent);

```

```
PACKAGE_NAME="package.json"
PACKAGE_CONTENTS='{"name": "app", "version": "1.0.0", "scripts": { "start": "METEOR_SETTINGS=$(cat settings.json) node main.js" } }'

```

The problem was that `writeJson` takes an object as content to be written rather than the string.

So, in the very original question, you need to change the quotes and parse the `packageContents` and pass the parsed content to the `writePackageJsonFile` function.
Try `await writePackageJsonFile(packageName, JSON.parse(packageContents));`, and change `contents: string` to `contents: any`, so that it accepts an object (Or recreate the object structure and assign that type).