https://authzed.com logo
#spicedb
writing schema to a JSON file
# spicedb
r

r3tarder

10/18/2023, 7:39 AM
Hey guys, can i write a schema from json file ?
v

vroldanbet

10/18/2023, 8:05 AM
No, the schema DSL has it's on language. The playground file format is, however, a YAML file (and the schema field in it is just a field). It would be fairly straight forward to convert from JSON to YAML. If what you are trying to do is
zed schema write
passing a JSON file, I'm afraid that won't work. What are you trying to achieve?
r

r3tarder

10/18/2023, 8:06 AM
i have 2 files, 1 is txt file to store the schema
1 json file to store the rule set like this, to check permission
I want to merge 2 file into 1
v

vroldanbet

10/18/2023, 9:57 AM
I dont understand what that file is for sorry, can you elaborate?
Are you looking to parse the schema and generate an AST that you serialize into your JSON file? Even if we provide APIs for that, those are subject to change the representation of the AST any time
r

r3tarder

10/18/2023, 9:59 AM
Let say is there anyway the schema can be read from json file ?
Indirectly
v

vroldanbet

10/18/2023, 10:00 AM
but what do you want from such a JSON file? the plaintext schema, or an abstract synstax tree-like representation?
I'm just not sure what problem you are trying to solve
r

r3tarder

10/18/2023, 10:01 AM
it's just a task that im on, so we have a json file that contain all information for the services
My leader want the schema to be include in the json also
i find everywhere but no luck
v

vroldanbet

10/18/2023, 10:04 AM
what is in the "all information for the services" file?
why do you need API to include the schema? can you just modify the JSON to add a new field that is
schema
and has the plaintext schema?
r

r3tarder

10/18/2023, 10:07 AM
the metadata,config, etc
"github.com/authzed/spicedb/pkg/namespace" What this pkg do ? i can some how write schema from it namespace.Namespace("foos/test", namespace.MustRelation("somerel", nil, namespace.AllowedRelation("foos/bars", "hiya")), ), `definition foos/test { relation somerel: foos/bars#hiya
v

vroldanbet

10/18/2023, 10:37 AM
It sounds like you want to parse a schema into an AST, serialize it into JSON, and then read it back. You can do that with the
compiler
package https://github.com/authzed/spicedb/blob/de719172d051a36ce17168473e595ecc5f9cfe7c/pkg/schemadsl/compiler/compiler.go#L45
r

r3tarder

10/19/2023, 2:39 AM
So the flow is, load JSON -> convert to spicedb code -> generate authorization schema -> load it into spicedb
@vroldanbet please help
v

vroldanbet

10/19/2023, 11:57 AM
I'm not sure you can do that out of the box, the schema go types are not annotated with json