Skip to content

Commit 4e8ee46

Browse files
author
James Brundage
committed
feat: Get-JsonLD ( Fixes #2 )
Decorating .'@graph' objects
1 parent ce3402e commit 4e8ee46

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Commands/Get-JsonLD.ps1

+14-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function Get-JsonLD {
99
.EXAMPLE
1010
# Want to get information about a movie? Linked Data to the rescue!
1111
Get-JsonLD -Url https://www.imdb.com/title/tt0211915/
12+
.EXAMPLE
13+
# Want information about an article? Lots of news sites use this format.
14+
Get-JsonLD https://www.thebulwark.com/p/mahmoud-khalil-immigration-detention-first-amendment-free-speech-rights
1215
#>
1316
[Alias('jsonLD','json-ld')]
1417
param(
@@ -41,13 +44,20 @@ application/ld\+json # The type that indicates linked d
4144
$match.Groups['JsonContent'].Value |
4245
ConvertFrom-Json
4346
) {
44-
if ($jsonObject.'@context' -and $jsonObject.'@type') {
47+
if ($jsonObject.'@type') {
4548
$schemaType = $jsonObject.'@context',$jsonObject.'@type' -join '/'
46-
$jsonObject.pstypenames.insert(0, $schemaType)
49+
$jsonObject.pstypenames.insert(0, $schemaType)
50+
}
51+
52+
if ($jsonObject.'@graph') {
53+
foreach ($graphObject in $jsonObject.'@graph') {
54+
if ($graphObject.'@type') {
55+
$graphObject.pstypenames.insert(0, $graphObject.'@type')
56+
}
57+
}
4758
}
4859
$jsonObject
4960
}
50-
}
51-
61+
}
5262
}
5363
}

0 commit comments

Comments
 (0)