5 CSV to JSON preprocessing

Overview

In this preprocessing step it is possible to convert CSV file data into JSON format. It’s supported in:

  • items (item prototypes)

  • low-level discovery rules

Configuration

To configure a CSV to JSON preprocessing step:

  • Go to the Preprocessing tab in item/discovery rule configuration

  • Click on Add

  • Select the CSV to JSON option

5 CSV to JSON preprocessing - 图1

The first parameter allows to set a custom delimiter. Note that if the first line of CSV input starts with “Sep=” and is followed by a single UTF-8 character then that character will be used as the delimiter in case the first parameter is not set. If the first parameter is not set and a delimiter is not retrieved from the “Sep=” line, then a comma is used as a separator.

The second optional parameter allows to set a quotation symbol.

If the With header row checkbox is marked, the header line values will be interpreted as column names (see Header processing for more information).

If the Custom on fail checkbox is marked, the item will not become unsupported in case of a failed preprocessing step. Additionally custom error handling options may be set: discard the value, set a specified value or set a specified error message.

Header processing

The CSV file header line can be processed in two different ways:

  • If the With header row checkbox is marked - header line values are interpreted as column names. In this case the column names must be unique and the data row should not contain more columns than the header row;

  • If the With header row checkbox is not marked - the header line is interpreted as data. Column names are generated automatically (1,2,3,4…)

CSV file example:

  1. Nr,Item name,Key,Qty
  2. 1,active agent item,agent.hostname,33
  3. "2","passive agent item","agent.version","44"
  4. 3,"active,passive agent items",agent.ping,55

A quotation character within a quoted field in the input must be escaped by preceding it with another quotation character.

Processing header line

JSON output when a header line is expected:

  1. [
  2. {
  3. "Nr":"1",
  4. "Item name":"active agent item",
  5. "Key":"agent.hostname",
  6. "Qty":"33"
  7. },
  8. {
  9. "Nr":"2",
  10. "Item name":"passive agent item",
  11. "Key":"agent.version",
  12. "Qty":"44"
  13. },
  14. {
  15. "Nr":"3",
  16. "Item name":"active,passive agent items",
  17. "Key":"agent.ping",
  18. "Qty":"55"
  19. }
  20. ]

No header line processing

JSON output when a header line is not expected:

  1. [
  2. {
  3. "1":"Nr",
  4. "2":"Item name",
  5. "3":"Key"
  6. "4":"Qty"
  7. },
  8. {
  9. "1":"1",
  10. "2":"active agent item",
  11. "3":"agent.hostname"
  12. "4":"33"
  13. },
  14. {
  15. "1":"2",
  16. "2":"passive agent item",
  17. "3":"agent.version"
  18. "4":"44"
  19. },
  20. {
  21. "1":"3",
  22. "2":"active,passive agent items",
  23. "3":"agent.ping"
  24. "4":"55"
  25. }
  26. ]