JSON to string transposing problem

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

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

what am i doing wrong?

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.

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


Thanks, i will try that :slight_smile:

M.f.g. Pascal