Skip to content

Commit 8219a73

Browse files
committed
update README with examples
1 parent 493bb53 commit 8219a73

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@
22

33
This Rust-based tool converts JSON data into RDF format, utilizing the `oxrdf` crate for RDF graph handling and `serde_json` for efficient JSON parsing. It supports lightweight, memory-efficient processing by reading JSON data values sequentially, which makes it suitable for large datasets.
44

5+
## Using the json2rdf CLI
6+
7+
This library includes a CLI utility for parsing JSON and generating N-Triple RDF using the `convert` subcommand. The binary can be built using `cargo build`.
8+
9+
```bash
10+
$ json2rdf convert --help
11+
Convert JSON to RDF format.
12+
13+
The `convert` command parses a JSON file, converts it to RDF triples using `serde_json` for parsing and `oxrdf` to construct the graph, and saves the output.
14+
15+
Usage: json2rdf convert [OPTIONS] --json-files <JSON_FILES>
16+
17+
Options:
18+
-n, --namespace <NAMESPACE>
19+
Namespace for RDF graph generation.
20+
21+
A custom namespace to prefix RDF resources created from JSON keys and values.
22+
23+
-j, --json-files <JSON_FILES>
24+
Path to input JSON file(s).
25+
26+
Provide the path to one or more JSON files that will be parsed and converted.
27+
28+
-o, --output-file <OUTPUT_FILE>
29+
Path to output file.
30+
31+
Optional: Specify the path to save the generated RDF data.
32+
33+
-h, --help
34+
Print help (see a summary with '-h')
35+
```
36+
37+
## Using the convert library
38+
39+
The conversion functionality can also be called directly in Rust. The library supports writing results to a file or building an in-memory `oxrdf::Graph`.
40+
41+
```rust
42+
use json2rdf::json_to_rdf;
43+
44+
// capture conversion results to file
45+
let results = json_to_rdf(&"tests/airplane.json".to_string(), &Some("http://example.com/ns#".to_string()), &Some("output.nt".to_string()));
46+
47+
// capture conversion results to an oxrdf::Graph
48+
let results = json_to_rdf(&"tests/airplane.json".to_string(), &Some("http://example.com/ns#".to_string()), &None);
49+
```
50+
551
## License
652

753
This project is licensed under either of

0 commit comments

Comments
 (0)