Skip to content

Commit

Permalink
Handle single and multi arr jsonpath transforms
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Nov 12, 2024
1 parent 291be9d commit dd54ba7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,18 @@ function getTransformedResult(
// the entire value. This may happen if full_response_path=false
// and the input is the entire result with nothing else to parse out.
// get() does not cover this case, so we override manually.
return path === '.'
? input
: mapEntry.value.startsWith(JSONPATH_ROOT_SELECTOR)
? // JSONPath transform
jsonpath.value(input, path)
: // Standard dot notation
get(input, path);
const result =
path === '.'
? input
: mapEntry.value.startsWith(JSONPATH_ROOT_SELECTOR)
? // JSONPath transform
jsonpath.query(input, path)
: // Standard dot notation
get(input, path);

// ML processors dynamically handle arrays vs. single values differently.
// We replicate that logic here to get consistent results
return Array.isArray(result) && result.length === 1 ? result[0] : result;
}

// Derive the collection of model inputs from the model interface JSONSchema into a form-ready list
Expand Down

0 comments on commit dd54ba7

Please sign in to comment.