Python Forum
json.load causing IndexError: list index out of range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json.load causing IndexError: list index out of range
#1
I'm trying to debug the ubuntu-mate-welcome python script which is refusing to load a valid json file.

I have validated the json file with jsonlint. However my experience with python is limited.

My environment is Ubuntu 18.04 aarch64 (arm64).

I have isolated the problem code in an example included here:

#! /usr/bin/python3
import sys
import json

print(sys.path)

json_path = ''

try:
    print('Reading index...')
    json_path = '/usr/share/ubuntu-mate-welcome/js/applications.json'
    with open(json_path) as data_file:
        print('Loading JSON.')
        index = json.load(data_file)
        print('LOADED JSON!!!!')
except Exception as e:
    index = None
    print('Software Index JSON is invalid or missing!')
    print(json_path)
The output is as follows:

Output:
['/home/odroid/Scripts', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages'] Reading index... Loading JSON. Software Index JSON is invalid or missing! /usr/share/ubuntu-mate-welcome/js/applications.json
However my example does not display the :

Error:
IndexError: list index out of range
So I am not certain I have faithfully reproduced the problem!

Output from jsonlint-php:

Output:
jsonlint-php /usr/share/ubuntu-mate-welcome/js/applications.json Valid JSON (/usr/share/ubuntu-mate-welcome/js/applications.json)
I have looked in the python path but cannot identify the json module referred to in the import statement.

How can I be certain I have the json module installed?
Reply


Messages In This Thread
json.load causing IndexError: list index out of range - by WallyZ - May-19-2019, 01:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  JSON Dump and JSON Load foxholenoob 8 1,201 Oct-12-2023, 07:21 AM
Last Post: foxholenoob
  IndexError: index 10 is out of bounds for axis 0 with size 10 Mehboob 11 2,254 Sep-14-2023, 06:54 AM
Last Post: Mehboob
Thumbs Down I hate "List index out of range" Melen 20 3,481 May-14-2023, 06:43 AM
Last Post: deanhystad
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,549 Mar-24-2023, 08:34 AM
Last Post: fullytotal
Exclamation IndexError: Replacement index 2 out of range for positional args tuple - help? MrKnd94 2 6,590 Oct-14-2022, 09:57 PM
Last Post: MrKnd94
  IndexError: list index out of range dolac 4 1,975 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  I'm getting a String index out of range error debian77 7 2,403 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,482 May-03-2022, 01:39 PM
Last Post: Anldra12
  TypeError: list indices must be integers or slices, not range Anldra12 2 2,664 Apr-22-2022, 10:56 AM
Last Post: Anldra12
  matplotlib x axis range goes over the set range Pedroski55 5 3,291 Nov-21-2021, 08:40 AM
Last Post: paul18fr

Forum Jump:

User Panel Messages

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