Register proto schema with REST api

The REST api supports registering schema versions for protobuf file if the body of the POST request is a JSON version of the proto file.

Where can I find the utility that converts .proto files to .json content? Some Confluent training videos make mention of a tool, but I cannot find that anywhere.

Hi @KenHuffman ,

I can’t find the file, but here’s the body of the script that you should be able to copy/paste into a file:

PROTO_JSON=$(awk '{gsub(/\n/,"\\\n"); gsub(/"/, "\\\"");print}' $1) \
    && SCHEMA="{\"schemaType\":\"PROTOBUF\",\"schema\":\"${PROTO_JSON}\"\n}" \
    && echo ${SCHEMA}

Here’s how you would execute it:

/ src/main/proto/purchase.proto 

You can adjust the parameter to be the path wherever you have your proto file


might be useful if anyone stumbles over the post like me and tries to use the mentioned script with a .proto file which has multiline comments like

this is a multiline comment

or single line comments like

// this is a single comment

included. this will not work with the provided script. one would need to adapt the script to remove these comments e.g. by using another sed or awk command. alternatively, remove the comments from your .proto file.

You can also use jq, such as

jq -n --rawfile schema order.proto '{schemaType: "PROTOBUF", schema: $schema}' | 
  curl http://localhost:8081/subjects/orders-value/versions --json @-
1 Like