","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"For cases when a connection to a URL is more complex i.e., where credentials may be required, you can still use "},{"type":"text","text":"load_json","code":true},{"type":"text","text":" with a configuration relation (e.g., "},{"type":"text","text":"config","code":true},{"type":"text","text":") that encodes integration information. The "},{"type":"text","text":"config","code":true},{"type":"text","text":" relation, which can be given any name, needs to specify the "},{"type":"text","text":":path","code":true},{"type":"text","text":" of the file to be imported and any integration parameters through "},{"type":"text","text":":integration","code":true},{"type":"text","text":"."}]},{"type":"p","children":[{"type":"text","text":"Here is an example using toy credentials for loading a JSON file from Azure:"}]},{"type":"code_block","lang":"rel","value":"def config[:path] = \"azure://myaccount.blob.core.windows.net/sascontainer/myfile.json\"\n\ndef config[:integration, :provider] = \"azure\"\ndef config[:integration, :credentials, :azure_sas_token] = \"sv=2014-02-14&sr=b&si=TestPolicy&sig=o%2B5%2F0C%2BLm7tWWftNKvQEGKHlSt%2Bfs8No7FZkUk5T%2Bv0%3D\"\n\ndef json = load_json[config]","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Finally, "},{"type":"text","text":"load_json","code":true},{"type":"text","text":" allows you to load data directly from a JSON string. This is similarly done using a "},{"type":"text","text":"config","code":true},{"type":"text","text":" relation, by specifying "},{"type":"text","text":":data","code":true},{"type":"text","text":" instead of "},{"type":"text","text":":path","code":true},{"type":"text","text":"."}]},{"type":"p","children":[{"type":"text","text":"Here is an example for loading data from a JSON string:"}]},{"type":"code_block","lang":"rel","value":"def config:data =\n\"\"\"\n{\n \"first_name\": \"John\",\n \"last_name\": \"Smith\",\n \"children's ages\": [10, 12, 3]\n}\n\"\"\"\n\ndef result = load_json[config]\ndef output = result","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Note that when a configuration relation is passed to "},{"type":"text","text":"load_json","code":true},{"type":"text","text":", it should specify either "},{"type":"text","text":":path","code":true},{"type":"text","text":" or "},{"type":"text","text":":data","code":true},{"type":"text","text":", but not both. You can also use "},{"type":"text","text":"parse_json","code":true},{"type":"text","text":" with a string directly, without needing to use a "},{"type":"text","text":"config","code":true},{"type":"text","text":" relation."}]},{"type":"h2","children":[{"type":"text","text":"Converting a Rel Relation to JSON"}],"id":"converting-a-rel-relation-to-json"},{"type":"p","children":[{"type":"text","text":"You can also convert data from an existing relation to a JSON string. This is done using "},{"type":"text","text":"json_string","code":true},{"type":"text","text":", which gives you the string representation of a relation that encodes JSON data."}]},{"type":"p","children":[{"type":"text","text":"Here is an example that creates the relation "},{"type":"text","text":"json_relation","code":true},{"type":"text","text":" and represents it as a JSON string:"}]},{"type":"code_block","lang":"rel","value":"def json_relation[:name] = \"Amira\"\ndef json_relation[:age] = 32\ndef json_relation[:height] = missing\ndef json_relation[:pets, :[], 1] = \"dog\"\ndef json_relation[:pets, :[], 2] = \"rabbit\"\n\ndef result = json_string[json_relation]","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"In the end, "},{"type":"text","text":"result","code":true},{"type":"text","text":" contains the JSON string:"}]},{"type":"code_block","lang":"javascript","value":"{\n \"name\": \"Amira\",\n \"age\": 32,\n \"height\": null,\n \"pets\": [\n \"dog\",\n \"rabbit\"\n ]\n}","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"You can find more information about importing, exporting, and managing JSON data in our "},{"type":"a","url":"https://docs.relational.ai/rel/how-to/json-import-export","title":null,"children":[{"type":"text","text":"JSON how-to guide"}]},{"type":"text","text":"."}]}],"_content_source":{"queryId":"src/content/resources/handling-json-data-in-rel.mdx","path":["resource","body"]}},"_content_source":{"queryId":"src/content/resources/handling-json-data-in-rel.mdx","path":["resource"]}}},"errors":null,"query":"\n query resource($relativePath: String!) {\n resource(relativePath: $relativePath) {\n ... on Document {\n _sys {\n filename\n basename\n breadcrumbs\n path\n relativePath\n extension\n }\n id\n }\n ...ResourceParts\n }\n}\n \n fragment ResourceParts on Resource {\n __typename\n title\n description\n date\n image\n categories\n authors {\n __typename\n name\n link\n }\n seo {\n __typename\n keywords\n description\n image\n image_alt\n canonical_url\n author\n published\n modified\n language\n robots\n site_name\n content_type\n }\n body\n}\n ","variables":{"relativePath":"handling-json-data-in-rel.mdx"}},"src/content/meta/meta.md":{"data":{"meta":{"_sys":{"filename":"meta","basename":"meta.md","breadcrumbs":["meta"],"path":"src/content/meta/meta.md","relativePath":"meta.md","extension":".md"},"id":"src/content/meta/meta.md","__typename":"Meta","banner":{"__typename":"MetaBanner","enabled":true,"content":{"type":"root","children":[{"type":"p","children":[{"type":"text","text":"Check out "},{"type":"a","url":"/resources/highlights-of-relationalai-at-snowflake-data-cloud-summit-2024","title":"SF summit highlights","children":[{"type":"text","text":"highlights"}]},{"type":"text","text":" of RelationalAI at "},{"type":"text","text":"Snowflake's Data Cloud Summit 2024!","bold":true}]}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","banner","content"]}},"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","banner"]}},"header":{"__typename":"MetaHeader","links":[{"__typename":"MetaHeaderLinks","text":"Product","url":"/product","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",0]}},{"__typename":"MetaHeaderLinks","text":"Company","url":"/company","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",1]}},{"__typename":"MetaHeaderLinks","text":"Docs","url":"/docs","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",2]}},{"__typename":"MetaHeaderLinks","text":"Resources","url":"/resources/all/1","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",3]}},{"__typename":"MetaHeaderLinks","text":"Get Started","url":"/get-started","style":"cta","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",4]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header"]}},"footer":{"__typename":"MetaFooter","sections":[{"__typename":"MetaFooterSections","name":"Product","links":[{"__typename":"MetaFooterSectionsLinks","text":"Overview","url":"/product","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Use Cases","url":"/product#for-problems-that-matter","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Capabilities","url":"/product#a-new-toolset","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",2]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0]}},{"__typename":"MetaFooterSections","name":"Resources","links":[{"__typename":"MetaFooterSectionsLinks","text":"Documentation","url":"/docs/get-started","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"News","url":"/resources/news/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Research","url":"/resources/research/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",2]}},{"__typename":"MetaFooterSectionsLinks","text":"Releases","url":"/resources/releases/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",3]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1]}},{"__typename":"MetaFooterSections","name":"About Us","links":[{"__typename":"MetaFooterSectionsLinks","text":"Our Company","url":"/company","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Contact Us","url":"/get-started","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Careers","url":"/careers","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",2]}},{"__typename":"MetaFooterSectionsLinks","text":"Legal","url":"/legal","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",3]}},{"__typename":"MetaFooterSectionsLinks","text":"GDPR","url":"/gdpr","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",4]}},{"__typename":"MetaFooterSectionsLinks","text":"Security & Trust","url":"https://trust.relational.ai/","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",5]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2]}}],"socials":[{"__typename":"MetaFooterSocials","text":"GitHub","url":"https://github.com/RelationalAI","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/github.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",0]}},{"__typename":"MetaFooterSocials","text":"LinkedIn","url":"https://www.linkedin.com/company/relationalai/about","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/linkedin.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",1]}},{"__typename":"MetaFooterSocials","text":"Twitter","url":"https://twitter.com/relationalai","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/twitter.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",2]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer"]}},"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta"]}}},"errors":null,"query":"\n query meta($relativePath: String!) {\n meta(relativePath: $relativePath) {\n ... on Document {\n _sys {\n filename\n basename\n breadcrumbs\n path\n relativePath\n extension\n }\n id\n }\n ...MetaParts\n }\n}\n \n fragment MetaParts on Meta {\n __typename\n banner {\n __typename\n enabled\n content\n }\n header {\n __typename\n links {\n __typename\n text\n url\n style\n }\n }\n footer {\n __typename\n sections {\n __typename\n name\n links {\n __typename\n text\n url\n }\n }\n socials {\n __typename\n text\n url\n icon\n }\n }\n}\n ","variables":{"relativePath":"./meta.md"}}};
globalThis.tina_info = tina;
})();
Handling JSON Data in Rel · RelationalAI
Check out highlights of RelationalAI at Snowflake's Data Cloud Summit 2024!
JSON is one of the most popular formats for data interchange today. It is widely used not only due to its simplicity and interoperability, but also because it allows users to easily represent (mostly hierarchical) relations between data.
At RelationalAI, we are excited to announce the support of JSON data through the load_json and json_string relations.
You can also specify a local file name instead of an S3 URL and the functionality will be identical. After loading, the JSON data are stored within the result relation as follows:
For cases when a connection to a URL is more complex i.e., where credentials may be required, you can still use load_json with a configuration relation (e.g., config) that encodes integration information. The config relation, which can be given any name, needs to specify the :path of the file to be imported and any integration parameters through :integration.
Here is an example using toy credentials for loading a JSON file from Azure:
Finally, load_json allows you to load data directly from a JSON string. This is similarly done using a config relation, by specifying :data instead of :path.
Here is an example for loading data from a JSON string:
Note that when a configuration relation is passed to load_json, it should specify either :path or :data, but not both. You can also use parse_json with a string directly, without needing to use a config relation.
Converting a Rel Relation to JSON
You can also convert data from an existing relation to a JSON string. This is done using json_string, which gives you the string representation of a relation that encodes JSON data.
Here is an example that creates the relation json_relation and represents it as a JSON string: