Blacksmith
Overview
IntegrationsPricing

Conditions & Wildcards

The examples in this document share the same Extraction result of a trigger of mode subscription:

{
  "status": "success",
  "body": {
    "name": {
      "first": "Tom",
      "last": "Anderson"
    },
    "age": 37,
    "children": [
      "Sara",
      "Alex",
      "Jack"
    ],
    "friends": [
      {
        "first": "Dale",
        "last": "Murphy",
        "age": 44,
        "nets": ["ig", "fb", "tw"]
      },
      {
        "first": "Roger",
        "last": "Craig",
        "age": 68,
        "nets": ["fb", "tw"]
      },
      {
        "first": "Jane",
        "last": "Murphy",
        "age": 47,
        "nets": ["ig", "tw"]
      }
    ]
  }
}

Conditions

In addition to the common Object & Arrays queries you can also query an array for the first match by using #(...), or find all matches with #(...)#. Queries support the ==, !=, <, <=, >, >= comparison operators, and the simple pattern matching % (like) and !% (not like) operators:

transformation:
  over_45: "{% query 'body.friends.#(age>45)#' %}"

Which outputs:

{
  "over_45": [
    {
      "first": "Roger",
      "last": "Craig",
      "age": 68,
      "nets": ["fb", "tw"]
    },
    {
      "first": "Jane",
      "last": "Murphy",
      "age": 47,
      "nets": ["ig", "tw"]
    }
  ]
}

Wildcards

A key may contain the special wildcard characters * and ?. The * will match on any zero+ characters, and ? matches on any one character:

transformation:
  first_child: "{% query 'body.child*.0' %}"

Which outputs:

{
  "first_child": "Sara"
}

Wildcards can be used inside conditions as well:

transformation:
  match: "{% query 'body.friends.#(first%D*).last' %}"

Which outputs:

{
  "match": "Murphy"
}
Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the repository. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Thank you for your contributions!