writing schema to a JSON file
# spicedb
r
Hey guys, can i write a schema from json file ?
v
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
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
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
Let say is there anyway the schema can be read from json file ?
Indirectly
v
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
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
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
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
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
So the flow is, load JSON -> convert to spicedb code -> generate authorization schema -> load it into spicedb
@vroldanbet please help
v
I'm not sure you can do that out of the box, the schema go types are not annotated with json