# utils Package

This page lists the exported helpers of `core/utils`, which convert between command text and decoded JSON values and walk nested paths.

## Functions

```go
import "github.com/pardnchiu/toriidb/core/utils"

func WalkKeys(obj any, subKeys []string) (any, bool)
func Atov(text string) any
func Vtoa(value any) string
func Vtof(value any) (float64, bool)
```

| Function | Behavior | Used by |
|---|---|---|
| `utils.WalkKeys` | Follows `subKeys` through decoded JSON: a `map[string]any` by field name, a `[]any` by decimal index. Returns `false` for a missing field, a non-numeric, negative, or out-of-range index, or a scalar in the middle of the path. An empty `subKeys` returns `obj` itself | `GetField`, `IncrField`, `filter.Cond` |
| `utils.Atov` | Converts command text to a JSON value: `null` → `nil`, `true`/`false` → `bool`, integer → `int64`, other number → `float64`, trimmed `{...}`/`[...]` that parses → object or array, anything else → `string` | `SetField` |
| `utils.Vtoa` | Renders a decoded value as text: `nil` → `(nil)`, whole `float64` without a decimal point, other `float64` in shortest form, `bool` as `true`/`false`, objects and arrays as compact JSON, other types with `%v` | `GetField`, `Incr`, `Exec`, `filter.Cond` |
| `utils.Vtof` | Returns a number as `float64` for `float64` and `int64` inputs; any other type, including numeric strings, returns `false` | `IncrField` |

## Round-Trip Rules

- `Vtoa` is what makes `1.0` compare equal to `1` in `QUERY`, because both render as `1`.
- `Atov` keeps integers as `int64`, but values decoded from stored JSON are `float64`; `Vtof` accepts both, so `INCR` on a JSON field works either way.
- A value that looks like JSON but fails to parse stays a string.

## Related Pages

- [Writing JSON Fields](/json-documents-writes)
- [QUERY Expressions](/querying-query)
- [filter](/api-reference-filter)
