YAML‐Parse Info - thepoopooman652/proishs-webtools GitHub Wiki

yaml-parse — YAML upload and preview

Overview

yaml-parse accepts YAML files (.yaml / .yml) and renders their content as an HTML table when the input represents a list of mappings or a mapping suitable for tabular display. Parsing uses a tiered approach: PHP's yaml extension when present, Symfony YAML parser if installed, and a pragmatic fallback parser for simple structures.

Files

  • index.php — Upload UI and parser. Accepts YAML uploads, chooses a parser implementation, normalizes the resulting PHP arrays/objects into rows and columns, and renders both a table and a raw pretty-printed preview.

Parsing strategy and normalization

  • Parser selection priority:

    1. PHP yaml_parse() (ext-yaml) if available.
    2. Symfony\Component\Yaml\Yaml::parse() when Symfony YAML is installed.
    3. A pragmatic fallback parser that handles common mapping/list structures for basic use cases.
  • Normalization rules:

    • If the YAML top-level value is a sequence (list) of mappings, each mapping becomes one table row and the union of keys forms the column set.
    • If the top-level value is a single mapping, keys become columns and values become a single row.
    • Sequence-of-scalars and other non-mapping types render into a single-column table unless transformed first.

Examples

  1. List of mappings (table rows)

Input:

- id: 1
	name: Alice
- id: 2
	name: Bob
	email: [email protected]

Result: table with columns id, name, email and two rows.

  1. Single mapping

Input:

id: 1
name: Example
tags:
	- alpha
	- beta

Result: single-row table with id, name, tags (tags column contains YAML-encoded array or stringified representation).

Usage and run steps

Start a local PHP server in the folder for quick verification:

cd 'C:\Users\Administrator\Documents\GitHub\proish-webtools\yaml-parse'
php -S 127.0.0.1:8000 -t .

Open http://127.0.0.1:8000/index.php and upload representative YAML documents (sequence of mappings, single mapping, NDYAML-like line-separated YAML if applicable).

Extensibility notes

  • For full YAML 1.2 coverage and advanced features (anchors, complex tags), install the pecl yaml extension or include Symfony YAML via Composer and prefer those parsers over the fallback.
  • Transformations: flattening nested mappings into dot-separated column names (e.g., address.cityaddress_city) is possible by applying a normalization step after parsing and before table rendering.

Changelog

  • 2025-11-06: Documented parser selection, normalization rules, examples, and run steps.

This README documents parser options, normalization behavior, and usage instructions for yaml-parse.