Implementation:Evidentlyai Evidently Legacy JSON Match Feature
| Knowledge Sources | |
|---|---|
| Domains | ML Monitoring, Data Validation, JSON Comparison |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Provides a generated feature that compares two JSON columns in a DataFrame for structural equality, ignoring key order.
Description
The JSONMatch class extends both FeatureTypeFieldMixin and GeneratedFeature to produce a categorical feature indicating whether two JSON strings in two specified columns are structurally equivalent. The comparison is performed by parsing both JSON strings into Python dictionaries using json.loads and comparing them for equality. This means key order is ignored, but values and structure must match exactly.
If either JSON string is invalid (raises ValueError or TypeError during parsing), the result for that row is False. The feature type defaults to ColumnType.Categorical.
The feature column is named using the pattern "JSON match for {first_column} and {second_column}" and the default display name follows the same pattern.
Usage
Use this feature when you need to verify that two columns containing JSON data are semantically equivalent. This is useful for comparing expected versus actual JSON outputs from models or APIs, for regression testing of structured outputs, or for data drift detection on JSON-valued columns.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File: src/evidently/legacy/features/json_match_feature.py
Signature
class JSONMatch(FeatureTypeFieldMixin, GeneratedFeature):
class Config:
type_alias = "evidently:feature:JSONMatch"
first_column: str
second_column: str
feature_type: ColumnType = ColumnType.Categorical
def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...
def _as_column(self) -> ColumnName: ...
def _feature_column_name(self): ...
Import
from evidently.legacy.features.json_match_feature import JSONMatch
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| first_column | str | Yes | Name of the first JSON column to compare |
| second_column | str | Yes | Name of the second JSON column to compare |
| feature_type | ColumnType | No | The output feature type (defaults to ColumnType.Categorical) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | pd.DataFrame | A single-column DataFrame with boolean values: True if the JSON objects in both columns are equal, False otherwise |
Usage Examples
from evidently.legacy.features.json_match_feature import JSONMatch
# Compare two JSON columns for equality
json_match_feature = JSONMatch(
first_column="expected_output",
second_column="actual_output"
)