Is there a way to get ory relationships from our p...
# general
b
Is there a way to get ory relationships from our project in the Zanzibar-like format used in the documentation? e.g.
Group:group1#members@User:user1
I see
ory parse relationships
for converting from that format, but I don't see a way to convert to that format
The reason I'm asking is because I found this interesting project that can visualize Ory relationships as a graph. But it takes the Zanzibar format as its input https://github.com/psauvage0/ketodot
I ended up writing a quick Powershell script for this
Copy code
# Define the input JSON file path and output file path

$inputFilePath = ".\relationships\relationships.json"
$outputFilePath = ".\relationships\relationships.keto"
$project_slug = "yourprojectslug"

ory list relationships --project $project_slug --page-size 10000 --format=json-pretty > $inputFilePath

# Read the JSON file
$jsonData = Get-Content -Path $inputFilePath | ConvertFrom-Json

# Initialize an array to store the Zanzibar notation relationships
$zanzibarRelationships = @()

# Iterate through each relationship in the JSON data
foreach ($relationship in $jsonData.relation_tuples) {
    # Extract the components of the relationship
    $namespace = $relationship.namespace
    $object_id = $relationship.object
    $relation = $relationship.relation
    $subject = $relationship.subject_id
    $subjectSet = $relationship.subject_set

    # Construct the Zanzibar notation
	# <https://storage.googleapis.com/gweb-research2023-media/pubtools/5068.pdf>
	# tuple:      object#relation@subject
	# object:     namespace:object_id
	# subject:    subject | subjectset
	# subjectset: object#relation

	if ($subjectSet) {
		$subject = $subjectSet.namespace + ":" + $subjectSet.object + "#" + $subjectSet.relation
	}

	$zanzibarNotation = "$namespace`:$object_id#$relation@$subject"
    $zanzibarRelationships += $zanzibarNotation
}

# Write the Zanzibar relationships to the output file
$zanzibarRelationships | Out-File -FilePath $outputFilePath -Encoding UTF8

#  ory parse relationships .\relationships\relationships.keto --project $project_slug
Write-Host "Conversion complete! Zanzibar relationships saved to $outputFilePath"
m
FYI @steep-lamp-91158 / @early-magician-18981 Maybe we can use something like ketodot in a sandbox so ppl can play around with relationships 🤔