# JSON to string transposing problem

**URL:** https://discourse.julialang.org/t/json-to-string-transposing-problem/108967
**Category:** Data
**Tags:** question, json
**Created:** [January 18, 2024, 3:02pm UTC](https://discourse.julialang.org/t/json-to-string-transposing-problem/108967 "2024-01-18T15:02:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Pascal\_Buhler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pascal_buhler/32/45582_2.png) [@Pascal\_Buhler](https://discourse.julialang.org/u/Pascal_Buhler)
#### Post date: [January 18, 2024, 3:02pm UTC](https://discourse.julialang.org/t/json-to-string-transposing-problem/108967/1 "2024-01-18T15:02:30Z")

</div>

i have this code and it gives me always a {} error. after this i wanna publish the code to string over a mqtt client.

```julia
LED = JSON.parse({"type": "led-ring", "payload": {"mode": 1, "duration": 10000, "speed": 100, "brightness": 255, "colors": ["0xFFFFFF", "0xFFFFFF", "0xFFFFFF"]}})

```

what am i doing wrong?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 18, 2024, 3:32pm UTC](https://discourse.julialang.org/t/json-to-string-transposing-problem/108967/2 "2024-01-18T15:32:58Z")

</div>

The input to `JSON.parse` should be a string. You aren’t passing a string, you are trying to input JavaScript syntax `{"type": "led-ring", …` directly into Julia, which won’t work. That is, you are confusing JSON _data_ with Julia _code_.

Try e.g.

```julia
LED = JSON.parse("""
{
  "type": "led-ring", 
  "payload": {"mode": 1, "duration": 10000, 
              "speed": 100, "brightness": 255, 
              "colors": ["0xFFFFFF", "0xFFFFFF", "0xFFFFFF"]}
}
""")

```

to wrap your JSON input in a Julia string. (I’ve added some line breaks for readability.)

PS. Please read [PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

---

<div class="post-metadata">

### Author: ![Pascal\_Buhler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pascal_buhler/32/45582_2.png) [@Pascal\_Buhler](https://discourse.julialang.org/u/Pascal_Buhler)
#### Post date: [January 19, 2024, 6:13am UTC](https://discourse.julialang.org/t/json-to-string-transposing-problem/108967/3 "2024-01-19T06:13:07Z")

</div>

Thanks, i will try that 🙂

M.f.g. Pascal
