Skip to content

feat: add JSON and utility functions (fromJSON, toJSON, keys, values, len)#18

Merged
jdx merged 1 commit intomainfrom
feat/json-functions
Jan 25, 2026
Merged

feat: add JSON and utility functions (fromJSON, toJSON, keys, values, len)#18
jdx merged 1 commit intomainfrom
feat/json-functions

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Jan 25, 2026

Summary

Adds built-in functions matching Go expr functionality:

  • fromJSON(string) - Parse JSON string into Value
  • toJSON(value) - Serialize Value to JSON string
  • keys(map) - Get array of map keys
  • values(map) - Get array of map values
  • len(array|string|map) - Get length of collection

Motivation

These functions are needed for mise to work with HTTP backend responses. Currently mise has a local workaround implementing fromJSON and keys as custom functions:

https://github.com/jdx/mise/blob/42d4a42b2ee2a2d31418f8dba98c1bdbffe31469/src/backend/version_list.rs#L58-L83

This was needed to fix HashiCorp tool version fetching which returns JSON responses that need to be parsed and have their keys extracted. Having these as built-in functions would be cleaner and benefit other users.

Reference: jdx/mise#7806

Changes

  • New src/functions/json.rs module with JSON conversion helpers
  • Added serde_json as a regular dependency (was only dev-dependency)
  • Comprehensive tests for all new functions

Test plan

  • All existing tests pass
  • New json_functions test covers all new functions
  • Tests for nested JSON, array access, and roundtrip conversion

🤖 Generated with Claude Code


Note

Introduces JSON and collection helpers to the default function set.

  • New src/functions/json.rs with converters between serde_json::Value and Value
  • Adds built-ins: fromJSON, toJSON, keys, values, len and registers them in Environment::new()
  • Adds serde_json as a runtime dependency
  • Extends tests to cover parsing, serialization, map keys/values, and length on arrays/strings/maps

Written by Cursor Bugbot for commit 507ad9e. This will update automatically on new commits. Configure here.

Add built-in functions matching Go expr functionality:

- fromJSON(string): Parse JSON string into Value
- toJSON(value): Serialize Value to JSON string
- keys(map): Get array of map keys
- values(map): Get array of map values
- len(array|string|map): Get length of collection

These functions are useful for working with JSON data in expressions,
such as parsing HTTP backend responses for version lists.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jdx jdx force-pushed the feat/json-functions branch from b22a699 to 507ad9e Compare January 25, 2026 14:30
@jdx jdx merged commit c4d2dfc into main Jan 25, 2026
4 checks passed
@jdx jdx deleted the feat/json-functions branch January 25, 2026 14:38
@github-actions github-actions Bot mentioned this pull request Jan 25, 2026
@jdx jdx mentioned this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant