0

I have a python script that ingests a .txt file and outputs a JSON file. I use linter to ensure that the format of my JSON file is accurate. After, I run my JSON file through this line in terminal:

browserify -g reactify ./directory.js -o ./bundle.js

Which takes the contents of my JSON file and bundles them with my 'directory.js' file and outputs the bundle as 'bundle.js'.

Bundle.js is kept in my static folder for a node.js server that I run. However, when I run my localhost to see the results of my process I receive the error message:

Uncaught SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data

But I am not sure why. Every step of my process seems to be accurate. If I change different things in my python file, the error message may update to something like 'unexpected s found at line...' or 'unexpected : found'... I can't discern where the problem is.

The only thing that I can think is that somehow, when I bundle my JSON with my directory.js, browserify or reactify is altering the JSON somehow

  • Assuming you have `JSON.parse(variable)` what is the output of doing `console.log(variable)`? – Jakub Kotrs Jun 05 '22 at 16:54
  • Hello! The output of doing console.log(variable) is the above error message "Uncaught SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data'. This is the code I use to require my JSON into my JS with browserify and reactify: ``` var allFoldersObject = require('./allFolders.json'); var allFoldersString = allFoldersObject[0]; var allFoldersParsed = JSON.parse(allFoldersString); const allFolders = allFoldersParsed; console.log(allFolders); ``` – hibiscushooligan Jun 05 '22 at 16:58
  • Let me know if there's anything else I can provide @JakubKotrs – hibiscushooligan Jun 05 '22 at 17:34
  • Put the console log before JSON.parse, it's crashing on that, so it doesn't even get to the console.log. – Jakub Kotrs Jun 06 '22 at 06:04
  • `var allFoldersObject = require('./allFolders.json'); console.log(allFoldersObject);` – Jakub Kotrs Jun 06 '22 at 06:05
  • @JakubKotrs the console.log(allFoldersObject) returns an Array with my JSON. It looks like this: Array [ "{ ' ': {'1': {'2': {'3': ... etc. – hibiscushooligan Jun 07 '22 at 14:07
  • That doesn't look like a JSON, because having it start with `Array [` is not a JSON. JSON would start with `[` directly. Can you check if the file is a valid JSON? Maybe post the first couple lines of it? – Jakub Kotrs Jun 07 '22 at 14:28
  • @JakubKotrs my JSON files does start with '[' alone. The console log simply adds the 'Array' when printing the contents of my JSON file. Console log considers it an array. 'Array [' is not part of the JSON file itself. My JSON file looks like: [ "{\"\": {\"1\": {\"2\": {\"3\": ... etc – hibiscushooligan Jun 08 '22 at 15:24

0 Answers0