Skip to main content

DataScan.from_json()

Restore a DataScan from a JSON string.

Usage

Source

DataScan.from_json(json_string)

The JSON string is the one produced by to_json(). It’s the counterpart to that method for profiles stored as text, such as in a database column or an API response. To read a JSON file, use load_from_json().

As with from_dict(), the restored scan has the statistics but not the data. Values that were written as strings in the JSON (such as dates) stay strings.

Parameters

json_string: str
A JSON string as produced by to_json().

Returns

DataScan
A restored DataScan instance.

Examples

Suppose the profile of the small_table dataset was stored as JSON text some time ago.

import pointblank as pb
import polars as pl

small_table = pb.load_dataset(dataset="small_table", tbl_type="polars")

stored_json = pb.DataScan(small_table, tbl_name="small_table").to_json()

Restoring it gives a DataScan that can be queried like the original one:

restored = pb.DataScan.from_json(stored_json)

restored.summary_data.select("colname", "n_missing", "n_unique")
shape: (8, 3)
colnamen_missingn_unique
stri64i64
"date_time"012
"date"011
"a"07
"b"012
"c"27
"d"012
"e"02
"f"03

The table name, row count, and every column’s statistics come from the JSON, so the original table isn’t needed to answer questions about it later.