Expand description
§OxJSON-LD
OxJSON-LD is a parser and serializer for JSON-LD.
The entry points of this library are the two JsonLdParser
and JsonLdSerializer
structs.
The parser is a work in progress. Only JSON-LD 1.0 is supported at the moment, JSON-LD 1.1 is not supported yet.
The parser supports two modes:
- regular JSON-LD parsing that needs to buffer the full file into memory.
- Streaming JSON-LD that can avoid buffering in a few cases.
- To enable it, call the
with_profile(JsonLdProfile::Streaming)
method.
Usage example counting the number of people in a JSON-LD file:
use oxrdf::{NamedNodeRef, vocab::rdf};
use oxjsonld::JsonLdParser;
let file = br#"{
"@context": {"schema": "http://schema.org/"},
"@graph": [
{
"@type": "schema:Person",
"@id": "http://example.com/foo",
"schema:name": "Foo"
},
{
"@type": "schema:Person",
"schema:name": "Bar"
}
]
}"#;
let schema_person = NamedNodeRef::new("http://schema.org/Person").unwrap();
let mut count = 0;
for triple in JsonLdParser::new().for_reader(file.as_ref()) {
let triple = triple.unwrap();
if triple.predicate == rdf::TYPE && triple.object == schema_person.into() {
count += 1;
}
}
assert_eq!(2, count);
§License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or
<http://www.apache.org/licenses/LICENSE-2.0>
) - MIT license (LICENSE-MIT or
<http://opensource.org/licenses/MIT>
)
at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Oxigraph by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Structs§
- Json
LdLoad Document Options - Used to pass various options to the LoadDocumentCallback.
- Json
LdParser - A JSON-LD parser.
- Json
LdPrefixes Iter - Iterator on the file prefixes.
- Json
LdProfile Set - Set of JSON-Ld profiles.
- Json
LdRemote Document - Returned information about a remote JSON-LD document or context.
- Json
LdSerializer - A JSON-LD serializer.
- Json
LdSyntax Error - An error in the syntax of the parsed file.
- Reader
Json LdParser - Parses a JSON-LD file from a
Read
implementation. - Slice
Json LdParser - Parses a JSON-LD file from a byte slice.
- Text
Position - A position in a text i.e. a
line
number starting from 0, acolumn
number starting from 0 (in number of code points) and a global fileoffset
starting from 0 (in number of bytes). - Writer
Json LdSerializer - Serializes a JSON-LD file to a
Write
implementation.
Enums§
- Json
LdError Code - A JSON-LD error code
- Json
LdParse Error - Error returned during JSON-LD parsing.
- Json
LdProfile - JSON-Ld profile.