Skip to main content
Glama

json-to-csv

Convert JSON strings to CSV format with customizable delimiters using this utility from the IT Tools MCP Server, simplifying data transformation for developers and administrators.

Instructions

Convert JSON to CSV format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
delimiterNoCSV delimiter
jsonYesJSON string to convert to CSV

Implementation Reference

  • The handler function for the 'convert_json_to_csv' tool. It parses the input JSON (expecting an array of objects), uses PapaParse to convert it to CSV with the specified delimiter, and returns the CSV content along with a summary, or an error message if conversion fails.
    }, async ({ json, delimiter = "," }) => { try { const Papa = (await import("papaparse")).default; const data = JSON.parse(json); if (!Array.isArray(data)) { throw new Error("JSON must be an array of objects"); } const csv = Papa.unparse(data, { delimiter }); return { content: [ { type: "text", text: `CSV:\n${csv}\n\nConversion Summary:\nRows: ${data.length}\nDelimiter: \"${delimiter}\"`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error converting JSON to CSV: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } }
  • The input schema for the tool, validating the 'json' parameter as a string and 'delimiter' as an optional string.
    inputSchema: { json: z.string().describe("JSON string to convert to CSV"), delimiter: z.string().describe("CSV delimiter").optional(), },
  • The registration function 'registerConvertJsonCsv' that registers the 'convert_json_to_csv' tool on the MCP server, including description, schema, annotations, and the inline handler.
    export function registerConvertJsonCsv(server: McpServer) { server.registerTool("convert_json_to_csv", { description: "Convert JSON to CSV format", inputSchema: { json: z.string().describe("JSON string to convert to CSV"), delimiter: z.string().describe("CSV delimiter").optional(), }, // VS Code compliance annotations annotations: { title: "Convert Json To Csv", description: "Convert JSON to CSV format", readOnlyHint: false } }, async ({ json, delimiter = "," }) => { try { const Papa = (await import("papaparse")).default; const data = JSON.parse(json); if (!Array.isArray(data)) { throw new Error("JSON must be an array of objects"); } const csv = Papa.unparse(data, { delimiter }); return { content: [ { type: "text", text: `CSV:\n${csv}\n\nConversion Summary:\nRows: ${data.length}\nDelimiter: \"${delimiter}\"`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error converting JSON to CSV: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } } ); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wrenchpilot/it-tools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server