JuliaIO / JSON.jl

JSON parsing and printing
Other
313 stars 101 forks source link

Issue converting JSON message to Julia string. #297

Closed logankilpatrick closed 4 years ago

logankilpatrick commented 4 years ago

Hey all, I have the following JSON message that I need as a string so I can send it to a Restful API.

{
    "attachments": [
        {
            "fallback": "Required plain-text summary of the attachment.",
            "color": "#36a64f"
        }
    ]
}

I cannot figure out the right way to convert this to a string so I can parse it and then pass it to the API.

logankilpatrick commented 4 years ago

I tried this:

attachment = "{\"attachments\" : [\"fallback\", \"Required plain-text summary of the attachment.\"]}"

but it still did not work.

quinnj commented 4 years ago
julia> using JSON

julia> x = Dict("attachments" => [Dict("fallback" => "Required plain-text summary of the attachment", "color" => "#36a64f")])
Dict{String,Array{Dict{String,String},1}} with 1 entry:
  "attachments" => Dict{String,String}[Dict("color"=>"#36a64f","fallback"=>"Required plain-text summary of the attachment")]

julia> JSON.json(x)
"{\"attachments\":[{\"color\":\"#36a64f\",\"fallback\":\"Required plain-text summary of the attachment\"}]}"
logankilpatrick commented 4 years ago

THANK YOU. That helped a lot