Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gjgd/jsonld-checker
A tool for checking the validity of JSON-LD objects
https://github.com/gjgd/jsonld-checker
checking hacktoberfest jsonld jsonld-context
Last synced: 2 months ago
JSON representation
A tool for checking the validity of JSON-LD objects
- Host: GitHub
- URL: https://github.com/gjgd/jsonld-checker
- Owner: gjgd
- License: mit
- Created: 2020-05-28T16:35:50.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-09-29T14:38:10.000Z (over 1 year ago)
- Last Synced: 2024-09-19T07:11:54.351Z (4 months ago)
- Topics: checking, hacktoberfest, jsonld, jsonld-context
- Language: TypeScript
- Homepage: https://www.jsonld-checker.com
- Size: 12.4 MB
- Stars: 14
- Watchers: 4
- Forks: 3
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSONLD Checker
https:/jsonld-checker.gjgd.xyz
## Getting started with the lib:
### Install
```bash
npm install jsonld-checker
```### Verifying JSON-LD
```js
const validJsonLd = {
"@context": [
"https://transmute-industries.github.io/universal-wallet/contexts/wallet-v1.json"
],
"id": "did:example:123456789abcdefghi",
"type": "Person",
"name": "John Smith",
"image": "https://via.placeholder.com/150",
"description": "Professional software developer for Acme Corp.",
"tags": [
"professional",
"person"
],
"correlation": [
"4058a72a-9523-11ea-bb37-0242ac130002"
]
};const resultOk = await jsonldChecker.check(validJsonLd);
/*
CheckResult { ok: true, error: { type: '', details: '' } }
*/
console.log(resultOk);
``````js
const invalidJsonLd = {
"@context": [
"https://transmute-industries.github.io/universal-wallet/contexts/wallet-v1.json"
],
"id": "did:example:123",
"type": [
"CachedDIDDocument"
],
"name": "Farming Sensor DID Document",
"image": "https://via.placeholder.com/150",
"description": "An IoT device in the middle of a corn field.",
"tags": [
"professional"
],
"correlation": [
"4058a72a-9523-11ea-bb37-0242ac130002"
],
"created": "2017-06-18T21:19:10Z",
"expires": "2026-06-18T21:19:10Z",
"didDocument": {
"@context": "https://w3id.org/did/v0.11",
"id": "did:example:123",
"assertionMethod": [
"did:example:123#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN"
],
"authentication": [
"did:example:123#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN"
],
"capabilityDelegation": [
"did:example:123#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN"
],
"capabilityInvocation": [
"did:example:123#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN"
],
"keyAgreement": [
{
"id": "did:example:123#zC5iai1sL93gQxn8LKh1i42fTbpfar65dVx4NYznYfG3Y5",
"type": "X25519KeyAgreementKey2019",
"controller": "did:example:123",
"publicKeyBase58": "6DrzegWwfw8Xg5MsHX95sVnJaPmtXP214B5X9hkG9oRs"
}
],
"publicKey": [
{
"id": "did:example:123#z6MksHh7qHWvybLg5QTPPdG2DgEjjduBDArV9EF9mRiRzMBN",
"type": "Ed25519VerificationKey2018",
"controller": "did:example:123",
"publicKeyBase58": "DqS5F3GVe3rCxucgi4JBNagjv4dKoHc8TDLDw9kR58Pz"
}
]
}
};const resultNotOk = await jsonldChecker.check(invalidJsonLd);
/*
CheckResult {
ok: false,
error: { type: 'MISSING_PROPERTIES_IN_CONTEXT', details: '["didDocument"]' }
}
*/
console.log(resultNotOk);
```### Passing a custom document loader
The lib supports passing a custom document loader to the check function:
```js
const privateContextUrl = 'https://my-domain.com/private-context.jsonld';
// A document with a private context that cannot be resolved by the default document loader
const docWithPrivateContext = {
'@context': privateContextUrl,
customProperty: 'customValue',
};// A custom document loader that can resolve a private context
const customDocumentLoader = async (url: string) => {
if (url === privateContextUrl) {
return {
contextUrl: null,
document: {
'@context': {
customProperty: 'https://custom-url.test',
},
},
documentUrl: url,
};
}
return {};
};const result = await check(docWithPrivateContext, customDocumentLoader);
/*
CheckResult { ok: true, error: { type: '', details: '' } }
*/
```# Useful links
- https://github.com/digitalbazaar/jsonld.js
- https://json-ld.org/playground/
- https://transmute-industries.github.io/universal-wallet/
- https://material-ui.com
- https://github.com/typescript-cheatsheets/react-typescript-cheatsheet#reacttypescript-cheatsheets