# How to get all the registered variable names of a \`JuMP\` model?

**URL:** <https://discourse.julialang.org/t/how-to-get-all-the-registered-variable-names-of-a-jump-model/113837>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package, jump\
**Created:** [May 4, 2024, 3:45pm UTC](https://discourse.julialang.org/t/how-to-get-all-the-registered-variable-names-of-a-jump-model/113837 "2024-05-04T15:45:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [May 4, 2024, 3:45pm UTC](https://discourse.julialang.org/t/how-to-get-all-the-registered-variable-names-of-a-jump-model/113837/1 "2024-05-04T15:45:42Z")

</div>

Is there any method to obtaining all the registered variable names (symbols) of a `JuMP` model? And, if the variables have been set [`String` names](https://jump.dev/JuMP.jl/stable/manual/variables/#Variable-names), how to get their original symbolic names?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 4, 2024, 9:45pm UTC](https://discourse.julialang.org/t/how-to-get-all-the-registered-variable-names-of-a-jump-model/113837/2 "2024-05-04T21:45:19Z")

</div>

See `object_dictionary(model)`, [JuMP · JuMP](https://jump.dev/JuMP.jl/stable/api/JuMP/#object_dictionary), which maps the registered name to the object.

There is no way to go from a variable to the symbolic name. You’ll need to invert the `object_dictionary` for that.

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [May 5, 2024, 3:52am UTC](https://discourse.julialang.org/t/how-to-get-all-the-registered-variable-names-of-a-jump-model/113837/3 "2024-05-05T03:52:50Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [July 30, 2025, 2:39am UTC](https://discourse.julialang.org/t/how-to-get-all-the-registered-variable-names-of-a-jump-model/113837/4 "2025-07-30T02:39:45Z")

</div>

~~I’d suggest directly add a `keys` method.~~ This would be way more convenient.

```julia
julia> using JuMP

julia> model = Model();

julia> @variable(model, x); @variable(model, y);

julia> model
├ ...omit lines...
└ Names registered in the model
  └ :x, :y

julia> :x ∈ keys(JuMP.object_dictionary(model))
true

julia> :z ∈ keys(JuMP.object_dictionary(model))
false

julia> :x ∈ keys(model)
ERROR: MethodError: no method matching keys(::Model)

```

Edit: I notice there is a `haskey` method, which is convenient

```julia
julia> m = [JuMP.Model(); JuMP.Model()];

julia> JuMP.@variable(m[1], x[1:2]); JuMP.@variable(m[2], y[1:3]);

julia> af = nt -> haskey(nt, :y);

julia> af(m[1])
false

julia> af(m[2])
true

```
