auto myValue = to!(string)(myJsonObject.opIndex("foo");

then, in the template, i want to print it, so i use

span Name: #{myValue}

the result, is "myValue" with the quotes.

Is this normal? Sorry, maybe it's a dumb question. I'm not so familiar
with json, mongodb, and the web applications :/

the json string looks like this:

{
"foo" : "bar",
"bar" : "foo",
"one" : "two",
...
}

Json.toString() currently converts back to a string in JSON format*.
To get just the value, you can use one of:

  • json.get!string
  • json.to!string (also converts numbers to string)
  • cast(string)json (same as get!string)

If you put the JSON object directly into the #{}, it will
automatically do the right thing, so no need to extract the values
beforehand.

Btw. instead of myJsonObject.opIndex("foo"), you can also write
myJsonObject["foo"], or even myJsonObject.foo as Json.opDispatch is
overloaded. So the example would become just #{myJsonObject.foo}.

I'll add some examples to the Json/Bson documentation as all the
overloaded operators make those structs a bit confusing.

  • I don't like how it's inconsistent with to!string(), but it seemed
    like the most practical definition before that existed...