description |
---|
Reads a JSON file into DataFrame. |
danfo.readJSON(source, options)
Parameters | Type | Description | Default |
source | Input file object, string file** **path or URL | Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, https, ftp, s3, gs, or a local path. Both relative and absolute paths are supported An input file object is also supported in the browser. |
|
options | Object | Configuration options for reading JSON files. Supported options: {
} |
{ |
The readJSON method can read JSON files from a local disk, over the internet, or directly from input file objects.
{% tabs %} {% tab title="Node.js" %}
const dfd = require("danfojs-node")
dfd.readJSON("./user_names.json")
.then(df => {
df.head().print()
}).catch(err=>{
console.log(err);
})
{% endtab %} {% endtabs %}
By specifying a valid URL, you can load JSON files from any location:
{% tabs %} {% tab title="Node.js" %}
const dfd = require("danfojs-node")
dfd.readJSON("https://raw.githubusercontentdatasets/master/finance-charts-apple.json")
.then(df => {
df.head().print()
}).catch(err=>{
console.log(err);
})
{% endtab %}
{% tab title="Browser" %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
<title>Document</title>
</head>
<body>
<script>
dfd.readJSON("https://raw.githubusercontentdatasets/master/finance-charts-apple.json")
.then(df => {
df.head().print()
}).catch(err=>{
console.log(err);
})
</script>
</body>
</html>
{% endtab %} {% endtabs %}
By specifying a valid file object, you can load a JSON file in the browser:
{% tabs %} {% tab title="Browser" %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
<title>Document</title>
</head>
<body>
<input type="file" id="file" name="file">
<script>
inputFile.addEventListener("change", async () => {
const jsonFile = inputFile.files[0]
dfd.readJSON(jsonFile).then((df) => {
df.print()
})
})
</script>
</body>
</html>
{% endtab %} {% endtabs %}