Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/csv/stringify.ts>stringify

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function stringify
import { stringify } from "https://deno.land/std@0.194.0/csv/stringify.ts";

Write data using CSV encoding.

Examples

Example 1

import {
  Column,
  stringify,
} from "https://deno.land/std@0.194.0/csv/stringify.ts";

type Character = {
  age: number;
  name: {
    first: string;
    last: string;
  };
};

const data: Character[] = [
  {
    age: 70,
    name: {
      first: "Rick",
      last: "Sanchez",
    },
  },
  {
    age: 14,
    name: {
      first: "Morty",
      last: "Smith",
    },
  },
];

let columns: Column[] = [
  ["name", "first"],
  "age",
];

console.log(stringify(data, { columns }));
// first,age
// Rick,70
// Morty,14

Parameters

data: DataItem[]

The source data to stringify. It's an array of items which are plain objects or arrays.

DataItem: Record<string, unknown> | unknown[]

const data = [
{
name: "Deno",
repo: { org: "denoland", name: "deno" },
runsOn: ["Rust", "TypeScript"],
},
];
optional
unnamed 1: StringifyOptions = [UNSUPPORTED]

Output formatting options

Returns

string