[Feature Improvement] Update JSON Loader to support loading data from more sources (#898)
Co-authored-by: Deven Patel <deven298@yahoo.com>
This commit is contained in:
@@ -2,9 +2,26 @@
|
||||
title: '📃 JSON'
|
||||
---
|
||||
|
||||
To add any json file, use the data_type as `json`. `json` allows remote urls and conventional file paths. Headers are included for each line, so if you have an `age` column, `18` will be added as `age: 18`. Eg:
|
||||
To add any json file, use the data_type as `json`. Headers are included for each line, so if you have an `age` column, `18` will be added as `age: 18`. Eg:
|
||||
|
||||
```python
|
||||
Here are the supported sources for loading `json`:
|
||||
```
|
||||
1. URL - valid url to json file that ends with ".json" extension.
|
||||
2. Local file - valid url to local json file that ends with ".json" extension.
|
||||
3. String - valid json string (e.g. - app.add('{"foo": "bar"}'))
|
||||
```
|
||||
|
||||
If you would like to add other data structures (e.x. list, dict etc.), do:
|
||||
```
|
||||
import json
|
||||
a = {"foo": "bar"}
|
||||
valid_json_string_data = json.dumps(a, indent=0)
|
||||
|
||||
b = [{"foo": "bar"}]
|
||||
valid_json_string_data = json.dumps(b, indent=0)
|
||||
```
|
||||
Example:
|
||||
```
|
||||
import os
|
||||
|
||||
from embedchain.apps.app import App
|
||||
@@ -25,8 +42,8 @@ response = app.query("What is the net worth of Elon Musk as of October 2023?")
|
||||
print(response)
|
||||
"As of October 2023, Elon Musk's net worth is $255.2 billion."
|
||||
```
|
||||
|
||||
```temp.json
|
||||
temp.json
|
||||
```
|
||||
{
|
||||
"question": "What is your net worth, Elon Musk?",
|
||||
"answer": "As of October 2023, Elon Musk's net worth is $255.2 billion, making him one of the wealthiest individuals in the world."
|
||||
|
||||
Reference in New Issue
Block a user