Python Forum
JSON file Loading issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: JSON file Loading issue (/thread-12490.html)



JSON file Loading issue - punna111 - Aug-27-2018

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



RE: JSON file Loading issue - buran - Aug-27-2018

make sure your json file is valid. e.g. https://jsonlint.com/


RE: JSON file Loading issue - rootVIII - Aug-27-2018

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.


RE: JSON file Loading issue - 0LI5A3A - Jun-28-2020

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


RE: JSON file Loading issue - buran - Jun-29-2020

@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.