danfo.read_json
Reads a JSON file into DataFrame.
danfo.read_json(source,) [source]
Text
Text
Text
Text
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:
{ method: The HTTP method to use.
headers: Additional headers to send with the request if reading JSON from remote url. Supports all the node-fetch options in Nodejs, and all fetch options in browsers.
}
{ method: "GET" }
Returns:
** **Promise. Resolves to DataFrame
The read_json method can read JSON files from a local disk, over the internet, or directly from input file objects.

Reading JSON files from local disk

Node.js
1
const dfd = require("danfojs-node")
2
3
dfd.read_json("./user_names.json")
4
.then(df => {
5
6
df.head().print()
7
8
}).catch(err=>{
9
console.log(err);
10
})
Copied!

Reading JSON files from a URL

By specifying a valid URL, you can load JSON files from any location:
Node.js
Browser
1
const dfd = require("danfojs-node")
2
3
dfd.read_json("https://raw.githubusercontentdatasets/master/finance-charts-apple.json")
4
.then(df => {
5
6
df.head().print()
7
8
}).catch(err=>{
9
console.log(err);
10
})
Copied!
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
8
<title>Document</title>
9
</head>
10
11
<body>
12
13
<script>
14
15
dfd.read_json("https://raw.githubusercontentdatasets/master/finance-charts-apple.json")
16
.then(df => {
17
18
df.head().print()
19
20
}).catch(err=>{
21
console.log(err);
22
})
23
24
</script>
25
</body>
26
27
</html>
Copied!

Reading an input file object in the browser

By specifying a valid file object, you can load a JSON file in the browser:
Browser
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
8
<title>Document</title>
9
</head>
10
11
<body>
12
<input type="file" id="file" name="file">
13
<script>
14
15
inputFile.addEventListener("change", async () => {
16
const jsonFile = inputFile.files[0]
17
dfd.read_json(jsonFile).then((df) => {
18
df.print()
19
})
20
})
21
22
</script>
23
</body>
24
25
</html>
Copied!
Last modified 17d ago