Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# convert AVRO to JSON

Tags:

json

c#

avro

Is there C# implementation to convert an AVRO deserialized

<GenericRecord>

back into a regular JSON format? I have successfully read the topic from Kafka and used the AvroDeserializer but I want to convert that into a JSON format.

Here's an example: Simple JSON:

{       
        "value": {
            "eventCreatedTimestamp": 1588694347577,
            "iouDecision": "PLANE",
            "iouDecisionReason": {
                "value": "Optimal"
            }
        }
    }

Same from the AVRO deserialized Generic.Record:

{Schema: 
{"type":"record","name":"TheCustomerDecisionEvent",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro","fields":
[{"name":"eventCreatedTimestamp","type":["null","long"]},
{"name":"iouDecision","type":["null",{"type":"enum",
"name":"TheType",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"symbols":["HRMR","FIELD","PLANE"]}]},
{"name":"iouDecisionReason","type":["null",{"type":"record","name":"iouDecisionReason",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"fields":[{"name":"value","type":["null","string"]}]}]}]}
,
 contents: { eventCreatedTimestamp: 1588694347577, 
 iouDecision: Schema: {"type":"enum","name":"TheType",
 "namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
 "symbols":["HRMR","FIELD","PLANE"]}, value: PLANE,
 iouDecisionReason: Schema: {"type":"record","name":"iouDecisionReason",
"namespace":"com.farmxxx.tst.property.service.options.iou.messaging.avro",
"fields":[{"name":"value","type":["null","string"]}]}, contents: { value: Optimal, }, }}

So the task is to get back to the Simple JSON from the AVRO Generic.Record.

like image 775
user3297833 Avatar asked Sep 14 '25 18:09

user3297833


1 Answers

The solution can be found using:

https://github.com/AdrianStrugala/AvroConvert

Avro2Json feature.

With this you can read a topic from Kafka and translate that into simple JSON. I use that simple JSON to pass onto other clients who don't want to know about AVRO record format etc.

Many thanks to the author of the AvroConvert Github repository.

like image 61
user3297833 Avatar answered Sep 17 '25 07:09

user3297833