#any->convert(from?: 'json'|yaml|'csv'|'markdown'|'latex', to?: 'json'|yaml|'csv'|html|'markdown'|'latex', header?: bool, as?: type, headers?: list, indented?: bool) → any
Modifie le format de la valeur. from : lit un texte écrit dans un format (json, yaml, csv, markdown ou latex), et to : écrit la valeur dans un format (json, yaml, csv, ou html, markdown et latex pour les documents) ; donnez les deux pour convertir l'un en l'autre. Lecture de csv :
not header lorsqu'il n'y a pas de ligne d'en-tête. Lecture de json, yaml ou csv : as : un type vérifie les données et les transforme en enregistrements. Écriture de csv : headers : choisit et ordonne les colonnes. Écriture de json : indented les répartit sur plusieurs lignes. ->from(type:) et ->to(type:) sont des raccourcis pour from: et to: utilisés seuls.| Paramètre | Prend |
|---|---|
from facultatif | l'un de ces mots : 'json'|yaml|'csv'|'markdown'|'latex' |
to optionnel | l'un de ces mots : 'json'|yaml|'csv'|html|'markdown'|'latex' |
header facultatif | un indicateur : header ou not header |
as facultatif | type |
headers facultatif | list |
indented optionnel | un indicateur : indented ou not indented |
Les arguments peuvent être nommés : ->convert(…, to: …, header: …).
Exemple
<!-- 'apple': the json text is read into a list of maps -->
<echo>{ '[{"fruit": "apple"}]'->convert(from: json)->first().fruit }</echo>
<let name="prices" value="[{ fruit: 'apple', price: 3 }, { fruit: 'plum', price: 5 }]" />
<!-- fruit,price on the first line, then one line a row: the maps' keys name the columns -->
<echo>{ $prices->convert(to: csv) }</echo>
<!-- 'apple: 3': yaml read, then written as json -->
<echo>{ 'apple: 3'->convert(from: yaml, to: json) }</echo>// 'apple': the json text is read into a list of maps
echo '[{"fruit": "apple"}]'->convert(from: json)->first().fruit
$prices = [{ fruit: 'apple', price: 3 }, { fruit: 'plum', price: 5 }]
// fruit,price on the first line, then one line a row: the maps' keys name the columns
echo $prices->convert(to: csv)
// 'apple: 3': yaml read, then written as json
echo 'apple: 3'->convert(from: yaml, to: json)