6 CSV uz JSON priekšapstrāde

Pārskats

Šajā priekšapstrādes solī ir iespējams pārveidot CSV faila datus JSON formātā. Tas tiek atbalstīts:

  • vienumos (vienumu prototipos)
  • zema līmeņa atklāšanas kārtulās

Konfigurācija

Lai konfigurētu CSV uz JSON pirmapstrādes soli:

Pirmais parametrs ļauj iestatīt pielāgotu atdalītāju. Ņemiet vērā, ka, ja pirmā CSV ievades rinda sākas ar "Sep=" un tai seko viens UTF-8 rakstzīme, tad šī rakstzīme tiks izmantota kā atdalītājs, ja pirmais parametrs nav iestatīts. Ja pirmais parametrs nav iestatīts un no rindas "Sep=" netiek iegūts atdalītājs, kā atdalītājs tiek izmantots komats.

Otrais, neobligātais parametrs ļauj iestatīt pēdiņu simbolu.

Ja ir atzīmēta izvēles rūtiņa With header row, galvenes rindas vērtības tiks interpretētas kā kolonnu nosaukumi (plašāku informāciju skatiet sadaļā Galvenes apstrāde).

Ja ir atzīmēta izvēles rūtiņa Custom on fail, vienums nekļūs neatbalstīts neveiksmīga pirmapstrādes soļa gadījumā. Papildus var iestatīt pielāgotas kļūdu apstrādes opcijas: atmest vērtību, iestatīt norādītu vērtību vai iestatīt norādītu kļūdas ziņojumu.

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:

Nr,Item name,Key,Qty
1,active agent item,agent.hostname,33
"2","passive agent item","agent.version","44"
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:

[
   {
      "Nr":"1",
      "Item name":"active agent item",
      "Key":"agent.hostname",
      "Qty":"33"
   },
   {
      "Nr":"2",
      "Item name":"passive agent item",
      "Key":"agent.version",
      "Qty":"44"
   },
   {
      "Nr":"3",
      "Item name":"active,passive agent items",
      "Key":"agent.ping",
      "Qty":"55"
   }
]

No header line processing

JSON output when a header line is not expected:

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