Reputation: 51
I am trying to read , loop through the json data and fetch values associated with table_name and schema
from google storage bucket in python but getting below error. Can anyone help why this error is coming and how to modify these code
file content: ABC.json
data = '{
"table_name": "abc.dataset.table1",
"schema": [
bigquery.SchemaField("COL1", "STRING"),
]
}'
blob = bucket.blob('delta/path/ABC.json')
downloaded_blob = blob.download_as_string()
downloaded_blob = downloaded_blob.decode("utf-8")
print(downloaded_blob)
data = json.loads(downloaded_blob)
print(data)
print(data['table_name'])
error :raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Upvotes: 0
Views: 606
Reputation: 1081
The reason seems to be the fact that your ABC.json
is not actually valid JSON.
In the schema
key, there's this :
[
bigquery.SchemaField("COL1", "STRING"),
]
JSON only allows certain types, and this bigquery.SchemaField
literal is not one of them.
Upvotes: 2