0

I am trying to invoke

expect_column_values_to_match_json_schema

as per

https://legacy.docs.greatexpectations.io/en/latest/autoapi/great_expectations/dataset/dataset/index.html#great_expectations.dataset.dataset.Dataset.expect_column_values_to_match_json_schema

jschema = {
        "type" : "object",
     "properties" : {
         "xyz" : {"type" : "string"}
     }
        }
df_ge.expect_column_values_to_match_json_schema(column='abc',json_schema=jschema,row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')

however i got this error

File "/some/path/lib/python3.7/site-packages/great_expectations/dataset/pandas_dataset.py", line 1554, in matches_json_schema
    val_json = json.loads(val)
  File "/usr/lib/python3.7/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict

so i tried

df_ge.expect_column_values_to_match_json_schema(column='abc',json_schema=json.loads(str(jschema)),row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')

but then i get

df_ge.expect_column_values_to_match_json_schema(column='pg',json_schema=json.loads(str(pgschema)),row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

how can i create a proper json object to feed to this method?

AbtPst
  • 7,778
  • 17
  • 91
  • 172

1 Answers1

1

There's no such thing as a "JSON object". JSON is a serialization format, so the only thing that can be JSON is a string of bytes. Such a string can be created with the very opposite of json.loads, namely json.dumps:

df_ge.expect_column_values_to_match_json_schema(column='pg',json_schema=json.dumps(pgschema),row_condition="a=='1' and b=='2' and c=='3'",condition_parser='pandas')
Thomas
  • 174,939
  • 50
  • 355
  • 478
  • thanks but using `dumps` gives me `TypeError: the JSON object must be str, bytes or bytearray, not dict` – AbtPst Oct 14 '21 at 18:35
  • @AbtPst Then please update your question with a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Thomas Oct 15 '21 at 19:15