Qu

json2csv

Builtin index · File I/O

result = json2csv(str)

Input: str · Output: result

What it is

str (string, JSON text) is converted to CSV text: exactly csvify(parse_json(str)).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = json2csv(str)
str stringnot documented yet
result string
Returns a string.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

t = parse_csv("product,price\nWidget,9.99\nGadget,4.50\n")

csv_text = csvify(t)
json_text = jsonify(t)

back_from_json = json2csv(json_text)   # csvify(parse_json(json_text))

print(back_from_json)

xml_from_csv = csv2xml(csv_text)       # xmlify(parse_csv(csv_text))

csv_from_xml = xml2csv(xml_from_csv)   # csvify(parse_xml(xml_from_csv))

print(csv_from_xml)

xml_from_json = json2xml(json_text)    # xmlify(parse_json(json_text))

json_from_xml = xml2json(xml_from_json) # the row-object array, not jsonify(parse_xml(...))

parsed = parse_json(json_from_xml)      # parse_json accepts that shape too -- back to a real Table

print(nrow(parsed))                     # 2

output
product,price
Widget,9.99
Gadget,4.5

product,price
Widget,9.99
Gadget,4.5

2

from file-io

How it works

Pairwise converters — literally csvify(parse_json(s)) etc., one line each. A shape that can't cross formats (e.g. a JSON array of bare scalars has no table shape) surfaces whichever clear error csvify/parse_json/etc. themselves already produce for that case — not a bespoke message here.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.