Home/Tools/@tpmjs/tools-yaml-parse

yamlParseTool

@tpmjs/tools-yaml-parse

Parse YAML text into JavaScript objects. Handles various YAML formats including objects, arrays, and scalars. Returns parsed data with validation status.

Official
data
v0.2.0
MIT

Interactive Playground

Test @tpmjs/tools-yaml-parse (yamlParseTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-yaml-parse
pnpm add @tpmjs/tools-yaml-parse
yarn add @tpmjs/tools-yaml-parse
bun add @tpmjs/tools-yaml-parse
deno add npm:@tpmjs/tools-yaml-parse

2. Import the tool

import { yamlParseTool } from '@tpmjs/tools-yaml-parse';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { yamlParseTool } from '@tpmjs/tools-yaml-parse';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { yamlParseTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
yaml
Required
Type: string

The YAML string to parse

Schema extracted: 1/1/2026, 8:18:26 AM

README

@tpmjs/tools-yaml-parse

Parse YAML text into JavaScript objects with validation and error handling.

Installation

npm install @tpmjs/tools-yaml-parse

Usage

import { yamlParseTool } from '@tpmjs/tools-yaml-parse';

// Use with AI SDK
const result = await yamlParseTool.execute({
  yaml: `
name: John Doe
age: 30
hobbies:
  - reading
  - coding
  - hiking
  `
});

console.log(result);
// {
//   data: { name: 'John Doe', age: 30, hobbies: ['reading', 'coding', 'hiking'] },
//   isValid: true,
//   metadata: { type: 'object', size: 3 }
// }

Features

  • Validation: Returns both parsed data and validation status
  • Error Handling: Graceful error messages for invalid YAML
  • Metadata: Provides type information and size of parsed data
  • Standards Compliant: Uses js-yaml library for full YAML 1.2 support

Input Schema

ParameterTypeRequiredDescription
yamlstringYesThe YAML string to parse

Output Schema

interface YamlParseResult {
  data: unknown;           // The parsed JavaScript object/value
  isValid: boolean;        // Whether parsing was successful
  error?: string;          // Error message if parsing failed
  metadata?: {
    type: string;          // Type of parsed data (object, array, string, etc.)
    size: number;          // Number of keys (objects) or items (arrays)
  };
}

Examples

Parse YAML Object

const result = await yamlParseTool.execute({
  yaml: 'name: Alice\nage: 25'
});
// { data: { name: 'Alice', age: 25 }, isValid: true, ... }

Parse YAML Array

const result = await yamlParseTool.execute({
  yaml: '- apple\n- banana\n- cherry'
});
// { data: ['apple', 'banana', 'cherry'], isValid: true, metadata: { type: 'array', size: 3 } }

Handle Invalid YAML

const result = await yamlParseTool.execute({
  yaml: 'invalid: yaml: syntax:'
});
// { data: null, isValid: false, error: 'bad indentation...' }

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
yaml
data
parser

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai