Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Character: Remove tabs, carriage returns, line feeds, and spaces when two or more are found consecutively.

Authoring Expressions

You MAY NOT alter the format of the standard response structure. For details on authoring expressions, refer to the Expression Exercise.

Expressions are very powerful, and can be very complex. it is recommended they are thoroughly tested with a variety of data sets. Below is an example that reformats two field names.

Code Block
breakoutModefull-width
(
    $moddedSummary:=SummaryFields.{"Key":$replace(Key,/^ADDRESS$/,"COMPANYADDRESS"), "Value":Value, "Confidence":Confidence, "Page":Page, "Sanitized":Sanitized,"Type":Type};
    $moddedSummary:=$moddedSummary.{"Key":$replace(Key,/^STREET$/,"COMPANYSTREET"), "Value":Value, "Confidence":Confidence, "Page":Page, "Sanitized":Sanitized,"Type":Type};

    {
        "Pages":$.Pages,
        "SummaryFields":$moddedSummary
    }
)
  1. Complex functions are wrapped in parens

  2. Variable assignment is handled with := and in the example above, line 2 initializes that variable and changes the ADDRESS field to COMPANYADDRESS while keeping the rest of the object structure intact

  3. Variables can be reused in expressions as demonstrated in line 3

    1. If you did not reuse the variable, you would lose the changes mage in line 2

  4. JSON is then output in the standard format