简体   繁体   中英

How to convert Json Array to Avro Schema

Hey i am new to Avro Schema space, needed to convert Jason Array into Avro Schema.

Below Jason is kind of client which serviceName along-with enabler-

If Enabler is true means that particular service is taken by client If Enabler is false means that particular service is not taken by client.

{
  "clientName": "Haven",
  "serviceDetailsList": [
    {
      "serviceName": "Service1",
      "enabled": true
    },
    {
      "serviceName": "Service2",
      "enabled": true
    },
    {
      "serviceName": "Service3",
      "enabled": true
    },
    {
      "serviceName": "Service4",
      "enabled": false
    },
    {
      "serviceName": "Service5",
      "enabled": false
    },
    {
      "serviceName": "Service6",
      "enabled": true
    }
 ]
}

I worked with below schema but not getting proper response.

"fields":[
    {"name": "serviceName",    "type": [ "Boolean", "false" ]  , "aliases":[ 
    "service1" ]
    },
    {"name": "serviceName",    "type": [ "Boolean", "false" ]  , "aliases":[ 
    "service2" ]
    }
  ]

Any help would be appreciated.

Thank you all of you,again i tried and able to get correct scheam. Correct Avro Schema is-

{
  "name": "modelData",
  "type": "record",
  "namespace": "com.hi.model",
  "fields": [
    {
      "name": "clientName",
      "type": "string"
    },
    {
      "name": "serviceDetailsList",
      "type": {
        "type": "array",
        "items": {
          "name": "serviceDetailsList_record",
          "type": "record",
          "fields": [
            {
              "name": "serviceName",
              "type": "string"
            },
            {
              "name": "enabled",
              "type": "boolean"
            }
          ]
        }
      }
    }
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM