Replies: 2 comments
-
|
It might seem confusing at first, but you need to remember that the data file for BigQuery is a newline-delimited JSON, not simple JSON. So the So you need to change: schema_map, error_logs = generator.deduce_schema(input_data=json.dumps(test))to schema_map, error_logs = generator.deduce_schema(input_data=[json.dumps(test)])Slightly off topic, but maybe relevant to you, you don't need to convert a python dict, into a JSON string, which gets converted back into a python dict by from bigquery_schema_generator.generate_schema import SchemaGenerator
import sys
import json
test = {
"a": "a",
"b": "20220101",
"c": "c",
"values": [{
"percentage": 3,
"values": [{
"a": "20220101",
"b": 100,
}]
}]
}
generator = SchemaGenerator(input_format='dict', infer_mode='NULLABLE')
schema_map, error_logs = generator.deduce_schema(input_data=[test])
schema = generator.flatten_schema(schema_map)
json.dump(schema, sys.stdout, indent=2)
print()which prints You can see some of the fields being interpreted as |
Beta Was this translation helpful? Give feedback.
-
|
This was mighty helpful. Thank you! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
this example json is valid but cannot be parsed to a schema:
Beta Was this translation helpful? Give feedback.
All reactions