run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
35.56k stars 5.02k forks source link

[Question]: JSONReader.load_data() is not able to handle parm extra_info? #15138

Open justinzyw opened 1 month ago

justinzyw commented 1 month ago

Question Validation

Question

it seems a bug. to me. I tried the sample (as below) in https://llamahub.ai/l/readers/llama-index-readers-json. however, it throw an error saying that JSONReader.load_data() is not able to handle parm extra_info

` from llama_index.readers.json import JSONReader

Initialize JSONReader

reader = JSONReader(

The number of levels to go back in the JSON tree. Set to 0 to traverse all levels. Default is None.

levels_back="<Levels Back>",
# The maximum number of characters a JSON fragment would be collapsed in the output. Default is None.
collapse_length="<Collapse Length>",
# If True, ensures that the output is ASCII-encoded. Default is False.
ensure_ascii="<Ensure ASCII>",
# If True, indicates that the file is in JSONL (JSON Lines) format. Default is False.
is_jsonl="<Is JSONL>",
# If True, removes lines containing only formatting from the output. Default is True.
clean_json="<Clean JSON>",

)

Load data from JSON file

documents = reader.load_data(input_file="", extra_info={}) `

dosubot[bot] commented 1 month ago

The extra_info parameter is indeed supported by the JSONReader.load_data() method. The issue might be due to incorrect usage or a different part of your code. Based on the provided code and documentation, the extra_info parameter should work as expected.

Here is the corrected code snippet:

from llama_index.readers.json import JSONReader

# Initialize JSONReader
reader = JSONReader(
    levels_back="<Levels Back>",
    collapse_length="<Collapse Length>",
    ensure_ascii="<Ensure ASCII>",
    is_jsonl="<Is JSONL>",
    clean_json="<Clean JSON>",
)

# Load data from JSON file
documents = reader.load_data(input_file="<Input File>", extra_info={})

Ensure that the parameters <Levels Back>, <Collapse Length>, <Ensure ASCII>, <Is JSONL>, <Clean JSON>, and <Input File> are correctly set according to your requirements. The extra_info parameter should be a dictionary, as shown in the example. If the issue persists, double-check that the JSONReader class and its load_data method are correctly imported and used as per the latest documentation [1][2].

To continue talking to Dosu, mention @dosu.