> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lionlang.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# object module: JS object interop in Lion

> Lion's object module lets you read properties, traverse dot-paths, stringify to JSON, list keys/values, construct classes, and call host methods.

The `object` module is the primary bridge between Lion programs and the JavaScript host environment. It covers everything from simple property access to calling methods deep in an object graph, constructing class instances, and serializing data to JSON strings.

## Property access

### `object/get`

Returns the value of a single key on an object.

```json theme={null}
["object/get", {"a": 1}, "a"]
```

Result: `1`

***

### `object/get-path`

Traverses a dot-separated path through nested objects and arrays. Numeric path segments index into arrays.

```json theme={null}
["object/get-path", {"a": {"b": {"c": 42}}}, "a.b.c"]
```

Result: `42`

Array indexing with a numeric segment:

```json theme={null}
["object/get-path", {"users": [{"name": "Ada"}, {"name": "Turing"}]}, "users.1.name"]
```

Result: `"Turing"`

<Note>
  Dot-path segments are split on `.`. A numeric segment (digits only) indexes into an array at that position. A non-numeric segment accesses an object key. Accessing a missing key or an out-of-bounds index produces a typed error.
</Note>

## Inspection

### `object/keys`

Returns an array of the string keys of an object.

```json theme={null}
["object/keys", {"a": 1, "b": 2}]
```

Result: `["a", "b"]`

***

### `object/values`

Returns an array of the values of an object.

```json theme={null}
["object/values", {"a": 1, "b": 2}]
```

Result: `[1, 2]`

## Serialization

### `object/json-stringify`

Serializes an object to a JSON string. Accepts the same arguments as `JSON.stringify`: the object, an optional replacer, and an optional indentation width.

```json theme={null}
["object/json-stringify", {"a": 1}, null, 2]
```

Result: `"{\n  \"a\": 1\n}"`

## Construction

### `object/new`

Calls a JavaScript constructor with the provided arguments and returns the new instance. The first argument must resolve to a function (class) in the environment.

```json theme={null}
["object/new", "SomeClass", "arg1", "arg2"]
```

<Note>
  `object/new` is mainly useful when Lion programs interact with host objects injected through a custom environment, such as UI framework classes or Node.js built-ins.
</Note>

## Method access and invocation

### `object/get-method`

Retrieves a method from an object and returns it bound to that object. Useful when you want to pass the method to a higher-order function.

```json theme={null}
["object/get-method", "obj", "methodName"]
```

***

### `object/call-method`

Retrieves and immediately calls a method on an object, passing any additional arguments.

```json theme={null}
["object/call-method", "obj", "methodName", 1, 2]
```

***

### `object/get-method-path`

Like `object/get-method`, but traverses a dot-separated path before retrieving the method. The method is bound to the object found at the parent path.

```json theme={null}
["object/get-method-path", "obj", "nested.methodName"]
```

***

### `object/call-method-path`

Traverses a dot-separated path, then calls the method at the end of the path with the provided arguments.

```json theme={null}
["object/call-method-path", "obj", "nested.methodName", 1, 2]
```

<Tip>
  In agent-style Lion programs it is common to alias `call-method-path` as `"()"` in the environment for a terser call syntax. See the host interop guide for a worked example.
</Tip>
