/act-json-compare

Apify act for comparing 2 JSON arrays of objects.

Primary LanguageJavaScriptApache License 2.0Apache-2.0

act-json-compare

Apify act for comparing 2 JSON arrays of objects.

This act fetches JSON arrays from two urls ("old" and "new"), compares them and creates a new result set based on the act settings. By default the final result set will contain only new and updated records.

INPUT

Input is a JSON object with the following properties:

{
  "oldJson": OLD_JSON_URL,
  "newJson": NEW_JSON_URL,
  "idAttr": ID_ATTRIBUTE_NAME,
  "return": WHICH_RECORDS_TO_RETURN,    // optional, default: "new, updated"
  "addStatus": ADD_TEXT_STATUS          // optional, default: false
  "statusAttr": STATUS_ATTR_NAME        // optional, default: "status"
  "addChanges": ADD_CHANGE_INFO         // optional, default: false
  "changesAttr": CHANGES_ATTR_NAME      // optional, default: "changes"
  "updatedIf": [                        // optional, column list
    "column_1",
    "column_2",
    ...
  ]
}

The idAttr parameter is a name of an attribute of each record, that will be used as it's ID.
The return parameter can be used to tell the act which records to include in the final result set. Possible values are new, updated, deleted and unchanged, you can provide more than one separated by comma.
The addStatus parameter sets if the act should add a status attribute to each of the resulting records.
If true, it's value will be one of NEW, UPDATED, DELETED or UNCHANGED, depending on the value of return parameter.
The addChanges parameter tells the act to include a list of columns that contained changes. This list will be added to a new changes column.
The changesAttr parameter overrides the default changes column name, where the changes will be stored.
The updatedIf parameter can contain an array of column names. If set, the record will be recognized as UPDATED if and only if there was a change in one of those columns. If addChanges is set to true, the changes array will contain the column names that had changes and are also present in the updatedIf array.