Method: Polars::IO#read_json

Defined in:
lib/polars/io/json.rb

#read_json(source, schema: nil, schema_overrides: nil, infer_schema_length: N_INFER_DEFAULT) ⇒ DataFrame

Read into a DataFrame from a JSON file.

Parameters:

  • source (Object)

    Path to a file or a file-like object.

  • schema (Object) (defaults to: nil)

    The DataFrame schema may be declared in several ways:

    • As a hash of \{name:type} pairs; if type is nil, it will be auto-inferred.
    • As an array of column names; in this case types are automatically inferred.
    • As an array of [name,type] pairs; this is equivalent to the hash form.

    If you supply an array of column names that does not match the names in the underlying data, the names given here will overwrite them. The number of names given in the schema should match the underlying data dimensions.

  • schema_overrides (Hash) (defaults to: nil)

    Support type specification or override of one or more columns; note that any dtypes inferred from the schema param will be overridden.

  • infer_schema_length (Integer) (defaults to: N_INFER_DEFAULT)

    The maximum number of rows to scan for schema inference. If set to nil, the full data may be scanned (this is slow).

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/polars/io/json.rb', line 25

def read_json(
  source,
  schema: nil,
  schema_overrides: nil,
  infer_schema_length: N_INFER_DEFAULT
)
  if Utils.pathlike?(source)
    source = Utils.normalize_filepath(source)
  end

  rbdf =
    RbDataFrame.read_json(
      source,
      infer_schema_length,
      schema,
      schema_overrides
    )
  Utils.wrap_df(rbdf)
end