Sorting Json struct from vibe.d

80 Views Asked by At

I faced a problem with wrong sorting JSON keys. I use mongo db and I need to send a creating user form command. vibe-d JSON:

            Json a2 = Json([
                    "createUser": Json(req.form["user"]),
                    "pwd": Json(req.form["password"]),
                    "roles": Json([
                            Json([
                                "role": Json(req.form["access"]),
                                "db": Json("3dstore")
                            ])
                        ])
                    ]);
            logInfo(a2.toString());

Output:

[main(Wbp2) INF] {"roles":[{"role":"readWrite","db":"3dstore"}],"createUser":"111","pwd":"1"}

std.json:

JSONValue a2 = JSONValue([
                    "createUser": JSONValue(req.form["user"]),
                    "pwd": JSONValue(req.form["password"]),
                    "roles": JSONValue([
                            JSONValue([
                                "role": JSONValue(req.form["access"]),
                                "db": JSONValue("3dstore")
                            ])
                        ])
                    ]);
            logInfo(a2.toString());

Output:

[main(vVOX) INF] {"createUser":"111","pwd":"1","roles":[{"db":"3dstore","role":"readWrite"}]}

Therefore I get an error in mongo output: "errmsg" : "no such command: 'roles'"

Any ideas?

0

There are 0 best solutions below