Add --raw flag to vals eval for JSONC, JSON5, and plain text support
Overview
This PR adds support for JSONC (JSON with comments), JSON5, and plain text files to the vals eval command by introducing a --raw flag. This addresses the feature request for a "loose mode" similar to envsubst that works with any text format while keeping the powerful ref+ syntax.
Problem
Currently, vals eval requires valid YAML or JSON input. This limitation prevents users from using vals with:
- JSONC files (JSON with comments) - commonly used in VSCode, tsconfig.json, etc.
- JSON5 files with flexible syntax (trailing commas, unquoted keys, etc.)
- Plain text configuration files
- Any text format that isn't structured YAML/JSON
Users who want to use vals for simple string substitution in configuration files had to either use vals get (which only works with single strings) or ensure their files are valid YAML/JSON.
Solution
Added a --raw flag to the vals eval command that treats input as raw text instead of parsing it as YAML/JSON. When enabled:
- Input is read as plain text without parsing
- The existing
vals.Get()function performs string substitution on the entire content - All
ref+expressions are replaced with their actual values - The original file format, comments, and structure are preserved
- Output format flag (
-o) is ignored since the format is preserved as-is
Usage Examples
Plain text configuration:
$ echo 'DATABASE_URL=ref+awsssm://prod/db/url' | vals eval -f - --raw
DATABASE_URL=postgres://prod-db:5432/myapp
JSONC with comments:
$ cat config.jsonc
{
// Database configuration
"database": "ref+vault://secret/data/db#/url",
/* API Keys */
"api_key": "ref+awssecrets://prod/api#/key"
}
$ vals eval -f config.jsonc --raw
{
// Database configuration
"database": "postgres://prod-db:5432/myapp",
/* API Keys */
"api_key": "sk-prod-1234567890"
}
JSON5 with trailing commas:
$ vals eval -f config.json5 --raw # Preserves JSON5 syntax
Implementation Details
-
New
RawInput()function inio.go- Reads raw text content from files or stdin, similar toInputs()but returns a string instead of YAML nodes -
Updated
vals evalcommand incmd/vals/main.go- Added--rawflag handling that bypasses YAML/JSON parsing and usesvals.Get()for text substitution -
Comprehensive tests - Added unit tests for
RawInput()and integration tests for raw mode with various file formats -
Documentation - Added "Raw Text Mode" section to README with practical examples
Benefits
-
No breaking changes - Existing functionality unchanged when
--rawis not used -
Minimal code changes - Reuses existing
vals.Get()logic for substitution - Format preservation - Comments, whitespace, and original structure maintained
- Flexible - Works with any text format, not just JSONC/JSON5
-
Intuitive - Behavior similar to
envsubstbut withvalsprovider power
Testing
- ✅ All existing tests pass
- ✅ New unit tests for
RawInput()function - ✅ Integration tests for raw mode with various formats
- ✅ Linter passes with 0 issues
- ✅ CodeQL security scan passes with 0 alerts
- ✅ Manual validation with JSONC, JSON5, and plain text files
Closes #XXX
Original prompt
This section details on the original issue you should resolve
<issue_title>Does vals tool also support JSONC , JSON5 or plain text files ?</issue_title> <issue_description>Json configuration with comments is heavily used in a lot of ecosystems . Is there a "loose" mode that could run on any text format ? This would be more similar
envsubstbut keeping the niceref+syntax .</issue_description>Comments on the Issue (you are @copilot in this section)
Fixes helmfile/vals#731
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.