python-avro-json-serializer
python-avro-json-serializer copied to clipboard
Unable to run the examples
@0x26res thank you for your guidance.
I am trying to run the sample code in the read me . Not able to. both code. (simple or "another"
import avro.io from avro import schema from avro.schema import SchemaFromJSONData as make_avsc_object from avro_json_serializer import AvroJsonSerializer
PS C:\a\Python\W\CSV> python dumpsa.py
Traceback (most recent call last):
File "dumpsa.py", line 44, in
PS C:\a\Python\W\CSV> python --version Python 3.8.6
was it in examples? given how you imported
from avro.schema import SchemaFromJSONData as make_avsc_object
you should do
make_avsc_object(schema_dict, avro.schema.Names())
without avro.schema
Still unable to run.
#########Code################
import avro.io from avro import schema from avro.schema import SchemaFromJSONData as make_avsc_object from avro_json_serializer import AvroJsonSerializer
need to serialize this data
data = { "ffloat": 1.0, "funion_null": None, "flong": 1, "fdouble": 2.0, "ffixed": "1234567890123456", "fint": 1, "fstring": "hi there", "frec": { "subfint": 2 } }
according to this schema:
schema_dict = { "fields": [{"name": "fint", "type": "int"}, {"name": "flong", "type": "long"}, {"name": "fstring", "type": "string"}, {"name": "ffixed", "size": 16, "type": {"name": "fixed_16", "size": 16, "type": "fixed"}}, {"name": "frec", "type": {"fields": [{"name": "subfint", "type": "int"}], "name": "Rec", "type": "record"}}, {"name": "funion_null", "type": ["int", "null"]}, {"name": "ffloat", "type": "float"}, {"name": "fdouble", "type": "double"}], "name": "all_field", "namespace": "com.some.thing", "type": "record" }
avro_schema = make_avsc_object(schema_dict, avro.schema.Names())
serializer = AvroJsonSerializer(avro_schema) json_str = serializer.to_json(data)
print (json_str)
################## ERROR ##################
PS C:\a\Python\ven\ven1\w\json> python jdumps1.py
Traceback (most recent call last):
File "jdumps1.py", line 47, in