Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::JsonSource.
JsonSource
JsonSource is a subclass of DataSource and
represents a JSON external data source that can be queried from
directly, such as Google Cloud Storage or Google Drive, even though
the data is not stored in BigQuery. Instead of loading or streaming
the data, this object references the external data source.
require"google/cloud/bigquery"bigquery=Google::Cloud::Bigquery.newrequire"google/cloud/bigquery"bigquery=Google::Cloud::Bigquery.newjson_url="gs://bucket/path/to/data.json"json_table=bigquery.externaljson_urldo|json|json.schemado|schema|schema.string"name",mode::requiredschema.string"email",mode::requiredschema.integer"age",mode::requiredschema.boolean"active",mode::requiredendenddata=bigquery.query"SELECT * FROM my_ext_table",external:{my_ext_table:json_table}# Iterate over the first page of resultsdata.eachdo|row|putsrow[:name]end# Retrieve the next page of resultsdata=data.nextifdata.next?
replace (Boolean) (defaults to: false) — Whether to replace the existing schema with
the new schema. If true, the fields will replace the existing
schema. If false, the fields will be added to the existing
schema. The default value is false.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# BigQuery API - Class Google::Cloud::Bigquery::External::JsonSource (v1.55.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.55.0 (latest)](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-JsonSource)\n- [1.54.0](/ruby/docs/reference/google-cloud-bigquery/1.54.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.53.0](/ruby/docs/reference/google-cloud-bigquery/1.53.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.52.1](/ruby/docs/reference/google-cloud-bigquery/1.52.1/Google-Cloud-Bigquery-External-JsonSource)\n- [1.51.1](/ruby/docs/reference/google-cloud-bigquery/1.51.1/Google-Cloud-Bigquery-External-JsonSource)\n- [1.50.0](/ruby/docs/reference/google-cloud-bigquery/1.50.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.49.1](/ruby/docs/reference/google-cloud-bigquery/1.49.1/Google-Cloud-Bigquery-External-JsonSource)\n- [1.48.1](/ruby/docs/reference/google-cloud-bigquery/1.48.1/Google-Cloud-Bigquery-External-JsonSource)\n- [1.47.0](/ruby/docs/reference/google-cloud-bigquery/1.47.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.46.1](/ruby/docs/reference/google-cloud-bigquery/1.46.1/Google-Cloud-Bigquery-External-JsonSource)\n- [1.45.0](/ruby/docs/reference/google-cloud-bigquery/1.45.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.44.2](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-External-JsonSource)\n- [1.43.1](/ruby/docs/reference/google-cloud-bigquery/1.43.1/Google-Cloud-Bigquery-External-JsonSource)\n- [1.42.0](/ruby/docs/reference/google-cloud-bigquery/1.42.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.41.0](/ruby/docs/reference/google-cloud-bigquery/1.41.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.40.0](/ruby/docs/reference/google-cloud-bigquery/1.40.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.39.0](/ruby/docs/reference/google-cloud-bigquery/1.39.0/Google-Cloud-Bigquery-External-JsonSource)\n- [1.38.1](/ruby/docs/reference/google-cloud-bigquery/1.38.1/Google-Cloud-Bigquery-External-JsonSource) \nReference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::External::JsonSource.\n\nJsonSource\n----------\n\n[JsonSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-JsonSource \"Google::Cloud::Bigquery::External::JsonSource (class)\") is a subclass of [DataSource](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-External-DataSource \"Google::Cloud::Bigquery::External::DataSource (class)\") and\nrepresents a JSON external data source that can be queried from\ndirectly, such as Google Cloud Storage or Google Drive, even though\nthe data is not stored in BigQuery. Instead of loading or streaming\nthe data, this object references the external data source. \n\nInherits\n--------\n\n- [Google::Cloud::Bigquery::External::DataSource](./Google-Cloud-Bigquery-External-DataSource)\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\njson_url = \"gs://bucket/path/to/data.json\"\njson_table = bigquery.external json_url do |json|\n json.schema do |schema|\n schema.string \"name\", mode: :required\n schema.string \"email\", mode: :required\n schema.integer \"age\", mode: :required\n schema.boolean \"active\", mode: :required\n end\nend\n\ndata = bigquery.query \"SELECT * FROM my_ext_table\",\n external: { my_ext_table: json_table }\n\n# Iterate over the first page of results\ndata.each do |row|\n puts row[:name]\nend\n# Retrieve the next page of results\ndata = data.next if data.next?\n```\n\nMethods\n-------\n\n### #fields\n\n def fields() -\u003e Array\u003cSchema::Field\u003e\n\nThe fields of the schema. \n**Returns**\n\n- (Array\\\u003c[Schema::Field](./Google-Cloud-Bigquery-Schema-Field)\\\u003e) --- An array of field objects.\n\n### #headers\n\n def headers() -\u003e Array\u003cSymbol\u003e\n\nThe names of the columns in the schema. \n**Returns**\n\n- (Array\\\u003cSymbol\\\u003e) --- An array of column names.\n\n### #param_types\n\n def param_types() -\u003e Hash\n\nThe types of the fields in the data in the schema, using the same\nformat as the optional query parameter types. \n**Returns**\n\n- (Hash) --- A hash with field names as keys, and types as values.\n\n### #schema\n\n def schema(replace: false) { |schema| ... } -\u003e Google::Cloud::Bigquery::Schema\n\nThe schema for the data. \n**Parameter**\n\n- **replace** (Boolean) *(defaults to: false)* --- Whether to replace the existing schema with the new schema. If `true`, the fields will replace the existing schema. If `false`, the fields will be added to the existing schema. The default value is `false`. \n**Yields**\n\n- (schema) --- a block for setting the schema \n**Yield Parameter**\n\n- **schema** ([Schema](./Google-Cloud-Bigquery-Schema)) --- the object accepting the schema \n**Returns**\n\n- ([Google::Cloud::Bigquery::Schema](./Google-Cloud-Bigquery-Schema))\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\njson_url = \"gs://bucket/path/to/data.json\"\njson_table = bigquery.external json_url do |json|\n json.schema do |schema|\n schema.string \"name\", mode: :required\n schema.string \"email\", mode: :required\n schema.integer \"age\", mode: :required\n schema.boolean \"active\", mode: :required\n end\nend\n```\n\n### #schema=\n\n def schema=(new_schema)\n\nSet the schema for the data. \n**Parameter**\n\n- **new_schema** ([Schema](./Google-Cloud-Bigquery-Schema)) --- The schema object.\n**Example** \n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\n\njson_shema = bigquery.schema do |schema|\n schema.string \"name\", mode: :required\n schema.string \"email\", mode: :required\n schema.integer \"age\", mode: :required\n schema.boolean \"active\", mode: :required\nend\n\njson_url = \"gs://bucket/path/to/data.json\"\njson_table = bigquery.external json_url\njson_table.schema = json_shema\n```"]]