CSV Import/Export
The CSV Import/Export can be used to extract and import data within the Data section of Structr.
The buttons for each operation can be found at the bottom of the screen and always relate to the currently selected Schema Type
The format of the CSV used for export and import uses line breaks to separate the data header and entities and ;
to separate specific values. The default quote character is "
Arrays and collections of remote nodes are encapsulated as a CSV line inside []
brackets. For these encapsulated CSV lines the default separation character is ,
and the quote character is "
but has to be escaped as \"
.
Export
The export button will produce a CSV string starting with the data header, followed by one line for each entity containing their respective data.
Import
The import form expects a data header with the addressed fields and the data for each entity.
It is important to note that fields can be provided optionally, unless required by the Schema.
The following example illustrates this by only specifying the name and aString attribute of the Type and some sample data.
In newer versions, the field separator and quote character can be customised via the UI. There is also a periodic commit feature which can be configured to commit after a configurable number of lines.
The import results in the following data:
Import Settings
The Import settings which can be configured via the UI are sent to the server as header fields and can be used via command line as well.
X-CSV-Field-Separator : defaults to ;
X-CSV-Quote-Character : defaults to "
X-CSV-Periodic-Commit : defaults to false
X-CSV-Periodic-Commit-Interval : defaults to 1000
The header parameters can easily be used as curl
parameters. They only need to be escaped according to your console environment:
curl -HX-User:admin -HX-Password:admin -HX-CSV-Periodic-Commit:true -HX-CSV-Periodic-Commit-Interval:125 -i -X POST localhost:8082/structr/csv/YourType -H "Content-Type: text/csv; charset=utf-8" --data-binary "@yourCsvFile.csv"
Note: Remote nodes are imported (and exported) as a simple array of UUIDs. Connecting newly created nodes via CSV is possible this way. Creating remote nodes, setting properties on them or setting properties on the relationship is not possible.