feat: add JSON and utility functions (fromJSON, toJSON, keys, values, len)#18
Merged
feat: add JSON and utility functions (fromJSON, toJSON, keys, values, len)#18
Conversation
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>
b22a699 to
507ad9e
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds built-in functions matching Go expr functionality:
fromJSON(string)- Parse JSON string into ValuetoJSON(value)- Serialize Value to JSON stringkeys(map)- Get array of map keysvalues(map)- Get array of map valueslen(array|string|map)- Get length of collectionMotivation
These functions are needed for mise to work with HTTP backend responses. Currently mise has a local workaround implementing
fromJSONandkeysas 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
src/functions/json.rsmodule with JSON conversion helpersserde_jsonas a regular dependency (was only dev-dependency)Test plan
json_functionstest covers all new functions🤖 Generated with Claude Code
Note
Introduces JSON and collection helpers to the default function set.
src/functions/json.rswith converters betweenserde_json::ValueandValuefromJSON,toJSON,keys,values,lenand registers them inEnvironment::new()serde_jsonas a runtime dependencyWritten by Cursor Bugbot for commit 507ad9e. This will update automatically on new commits. Configure here.