# ws.state.put

Replaces the value at --key with --value, creating the objects above it

# ws.state.put

```
ws.state.put --key TEXT --value JSON [--room TEXT] [--batch] [--visible-to TEXT…] → state
```

Replaces the value at `--key` with `--value`, creating the objects above it. The room's shared state is what every client of the room mirrors. `--key` is a JSON pointer; a part from the payload is written with {{ }}, and a segment that resolves empty is refused. `--room` is an exact room (a room that is not open is `FW_NODE_WS_ROOM_NOT_OPEN`); without it the room is the one of the [`trigger.room`](/nodes/trigger/trigger.room.md) that started the run. A change past the room's `--max-state` is refused. Clients get a `patch` of only what changed at once, or with `--batch` on the room's 33 ms tick (in a tick room, after the tick). `--visible-to <tag>` (repeatable; put and update) limits the path and all under it to the sessions holding one of the tags ([`ws.session.tag`](/nodes/ws/ws.session.tag.md)) — fog of war, a private hand: the others are never sent it. A put without it makes the path visible to all; an update without it keeps its limit. Adds `state: { key, room }` and keeps the rest of the payload. Sending an event without changing state is [`ws.message.send`](/nodes/ws/ws.message.send.md).

## Flags

- `--key` (required): A JSON pointer into the room's state: /players/{{ input.room.session_id }}. A segment that resolves empty is refused.
- `--value` (required): What to write — a literal or {{ expr }}.
- `--room`: The exact room; default: the room of the trigger.room that started the run.
- `--batch`: Let the room's 33 ms tick send the change, at most once a tick — for 10+ changes a second.
- `--visible-to`: Only sessions holding one of these tags see this path (repeat for several; none: visible to all). Tags come from ws.session.tag.

## Examples

### Keep the last move

```
| ws.state.put --key /last_move --value "{{ input.room.payload }}"
```

It answers:

```json
{
  "state": {
    "key": "/last_move",
    "room": "lobby"
  }
}
```

### Deal a hand only its seat sees

```
| ws.state.put --key "/hands/{{ input.room.session_id }}" --value "{{ input.room.payload.cards }}" --visible-to "seat:{{ input.room.payload.seat }}"
```

After `ws.session.tag --tag seat:2` on that session; every other session's view has no `/hands/ws-1f0c`.

It answers:

```json
{
  "state": {
    "key": "/hands/ws-1f0c",
    "room": "table-7"
  }
}
```
