Python Forum
JSON file Loading issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSON file Loading issue
#1
Hi all,

I am getting below error, tried multiple ways, which are available online.
but still i am getting the error. could you please let me what is reason for error.
and how can i fix it.

Code i am running:
import nltk
from nltk.stem.lancaster import LancasterStemmer
import numpy as np
import tflearn
import tensorflow as tf
import random
import json
import string
import unicodedata
import sys

# a table structure to hold the different punctuation used
tbl = dict.fromkeys(i for i in range(sys.maxunicode)
                    if unicodedata.category(chr(i)).startswith('P'))


# method to remove punctuations from sentences.
def remove_punctuation(text):
    return text.translate(tbl)

# initialize the stemmer
stemmer = LancasterStemmer()
# variable to hold the Json data read from the file
data = None

# read the json file and load the training data
with open('D:\\News wype\\Sample_Data.json', 'r', encoding='utf8', errors='ignore') as json_data:
    data = json.load(json_data)
    print(data)
error I am getting:

Error:
File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) JSONDecodeError: Invalid \escape
Reply
#2
make sure your json file is valid. e.g. https://jsonlint.com/
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Is there a file path in your json file?

Sometimes with Windows it's much less troublesome to just use fwd slashes in your absolute paths... like in Linux.
Reply
#4
Hello,

try to change the put like this

D://News wype//Sample_Data.json when you load the data from path in python you need to change the \ with / .
Thanks
Reply
#5
@0LI5A3A, it's an old thread but because you necro-post - there is nothing wrong with using double backslash in path - this will escape the backslash in windows path. Basically there are three ways to do it:
  • using raw-string
  • using double backslash, to escape the backaslash and possible escape sequence.
  • using forward slash, like you suggest.

In addition - the traceback show that the file is found (i.e. no problem with path) and there is problem with the content of the file.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP! Importing json file into csv into jupyter notebook vilsef 2 2,531 Jan-22-2021, 11:06 AM
Last Post: snippsat
  Loading multiple JSON files to create a csv 0LI5A3A 0 2,081 Jun-28-2020, 10:35 PM
Last Post: 0LI5A3A
  Indirectlty convert string to float in JSON file WBPYTHON 6 5,830 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  Help batch converting .json chosen file to MySQL BrandonKastning 2 2,284 Mar-14-2020, 09:19 PM
Last Post: BrandonKastning
  memory issue loading movie to numpy array djf123 1 2,245 Nov-07-2019, 06:19 AM
Last Post: ThomasL
  save my sensor data from the bme680 into a json or csv file Plastefuchs84 1 3,103 Aug-23-2019, 03:04 AM
Last Post: Plastefuchs84
  loading a csv file into python from pandas. Variable is not recognized vijjumodi 2 2,877 Apr-19-2019, 04:09 AM
Last Post: kus
  Merge JSON files prioritizing the updated values from most recent file nebulae 0 2,519 Apr-17-2019, 10:15 AM
Last Post: nebulae
  reading, modifying and writing json file metalray 2 10,883 Jun-06-2018, 03:09 PM
Last Post: metalray
  Issue in getting the required data from nested json and store it in a pandas datafram PrateekG 2 3,276 May-20-2018, 11:25 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020