Bottom Page

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
buran wrote Aug-27-2018, 02:08 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have fixed tags for you.
See BBcode help for more info.
Quote
#2
make sure your json file is valid. e.g. https://jsonlint.com/
Quote
#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.
Quote
#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
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Loading multiple JSON files to create a csv 0LI5A3A 0 78 Jun-28-2020, 10:35 PM
Last Post: 0LI5A3A
  Indirectlty convert string to float in JSON file WBPYTHON 6 369 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  Help batch converting .json chosen file to MySQL BrandonKastning 2 311 Mar-14-2020, 09:19 PM
Last Post: BrandonKastning
  memory issue loading movie to numpy array djf123 1 329 Nov-07-2019, 06:19 AM
Last Post: ThomasL
  save my sensor data from the bme680 into a json or csv file Plastefuchs84 1 628 Aug-23-2019, 03:04 AM
Last Post: Plastefuchs84
  loading a csv file into python from pandas. Variable is not recognized vijjumodi 2 801 Apr-19-2019, 04:09 AM
Last Post: kus
  Merge JSON files prioritizing the updated values from most recent file nebulae 0 794 Apr-17-2019, 10:15 AM
Last Post: nebulae
  reading, modifying and writing json file metalray 2 7,678 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 1,465 May-20-2018, 11:25 AM
Last Post: scidam
  loading a 3D array from a bin file Mark3232 1 1,313 May-04-2018, 11:36 AM
Last Post: j.crater

Forum Jump:


Users browsing this thread: 1 Guest(s)