#any->convert(from?: 'json'|yaml|'csv'|'markdown'|'latex', to?: 'json'|yaml|'csv'|html|'markdown'|'latex', header?: bool, as?: type, headers?: list, indented?: bool) → any
값의 형식을 바꿔요. from: 은 특정 형식(json, yaml, csv, markdown 또는 latex)으로 작성된 텍스트를 읽고, to: 는 값을 한 형식(json, yaml, csv, 문서용 html, markdown, latex)으로 써요. 둘 다 지정하면 한 형식을 다른 형식으로 바꿔요. 헤더 줄이 없는 csv를 읽을 때는
not header을 사용해요. json, yaml, csv를 읽을 때 as: 는 형식으로 데이터를 검사해 레코드로 바꿔요. csv를 쓸 때 headers: 는 열을 골라 순서를 정해요. json을 쓸 때 indented 는 여러 줄로 나눠 써요. ->from(type:)과 ->to(type:)은 각각 from:과 to:를 단독으로 쓰는 축약형이에요.| 매개변수 | 받는 값 |
|---|---|
from 선택 | 다음 단어 중 하나: 'json'|yaml|'csv'|'markdown'|'latex' |
to 선택 사항 | 다음 단어 중 하나: 'json'|yaml|'csv'|html|'markdown'|'latex' |
header 선택 사항 | 플래그: header 또는 not header |
as 선택 | type |
headers 선택 | list |
indented 선택 사항 | 플래그: indented 또는 not indented |
인수는 이름을 붙여 지정할 수 있어요: ->convert(…, to: …, header: …).
예시
<!-- '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)