json.mdx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ---
  2. title: '📃 JSON'
  3. ---
  4. To add any json file, use the data_type as `json`. Headers are included for each line, so for example if you have a json like `{"age": 18}`, then it will be added as `age: 18`.
  5. Here are the supported sources for loading `json`:
  6. ```
  7. 1. URL - valid url to json file that ends with ".json" extension.
  8. 2. Local file - valid url to local json file that ends with ".json" extension.
  9. 3. String - valid json string (e.g. - app.add('{"foo": "bar"}'))
  10. ```
  11. <Tip>
  12. If you would like to add other data structures (e.g. list, dict etc.), convert it to a valid json first using `json.dumps()` function.
  13. </Tip>
  14. ## Example
  15. <CodeGroup>
  16. ```python python
  17. from embedchain import App
  18. app = App()
  19. # Add json file
  20. app.add("temp.json")
  21. app.query("What is the net worth of Elon Musk as of October 2023?")
  22. # As of October 2023, Elon Musk's net worth is $255.2 billion.
  23. ```
  24. ```json temp.json
  25. {
  26. "question": "What is your net worth, Elon Musk?",
  27. "answer": "As of October 2023, Elon Musk's net worth is $255.2 billion, making him one of the wealthiest individuals in the world."
  28. }
  29. ```
  30. </CodeGroup>