# Merge Dictionaries with values of type Vector

**URL:** <https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703>\
**Category:** General Usage\
**Tags:** question, dictionary, merge\
**Created:** [May 24, 2024, 9:21pm UTC](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703 "2024-05-24T21:21:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sardinecan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sardinecan/32/29141_2.png) [@sardinecan](https://discourse.julialang.org/u/sardinecan)\
**Post date:** [May 24, 2024, 9:21pm UTC](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703/1 "2024-05-24T21:21:40Z")

</div>

Hi everyone,

I try to merge two dictionaries and one of them contains a vector value. Unfortunately, all the merging methods used return the same error:

```julia
body = Dict(
    :scope => "deposited"
  )
# an optional parameter for a request to an API
statusParameter = Dict(
    :status => ["pending"]
  )

# body[:status] = ["pending"]
# setindex!(body, ["pending"], :status)
merge!(body, statusParameter)

```

`Cannot `convert` an object of type Vector{String} to an object of type String`

I would like to achieve something like:

```julia
Dict{Symbol, Any} with 2 entries:
  :status => ["pending"]
  :scope => "deposited"

```

Does anyone know how to do it?

Best,  
Josselin.

---

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [May 24, 2024, 9:29pm UTC](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703/2 "2024-05-24T21:29:09Z")

</div>

You need to start with a Dict that has the right type, so you could do:

```julia
julia> blank = Dict{Symbol, Any}()
Dict{Symbol, Any}()

julia> merge!(blank, body, statusParameter)
Dict{Symbol, Any} with 2 entries:
  :status => ["pending"]
  :scope => "deposited"

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 25, 2024, 6:25am UTC](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703/3 "2024-05-25T06:25:57Z")

</div>

Or you can merge out-of-place, and Julia will find an appropriate type covering both cases (here it chooses `Any`):

```julia
julia> merge(body, statusParameter)
Dict{Symbol, Any} with 2 entries:
  :status => ["pending"]
  :scope => "deposited"

```

---

<div class="post-metadata">

**Author:** ![sardinecan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sardinecan/32/29141_2.png) [@sardinecan](https://discourse.julialang.org/u/sardinecan)\
**Post date:** [May 25, 2024, 6:42am UTC](https://discourse.julialang.org/t/merge-dictionaries-with-values-of-type-vector/114703/4 "2024-05-25T06:42:10Z")

</div>

@Satvik and @gdalle, Thanks to both of you! I thought merge() and merge!() worked the same way, with no type needed…  
Best,
