0

I want to create following json request:

{
  "Value1":{},
  "Value2":"some string value"
}

to achieve this I have tried following code in cpp:

json::value &refRequest
json::value jRequest = json::value();
refRequest[requestKey::Value1] = json::value(json::value::object()); //for creating empty object
refRequest[requestKey::Value2] = json::value::string("some string");

but it gives output as:

{
  "Value1":},
  "Value2":"some string value"
}

if you observe, instead of returning empty object as {} it gives the output as } and this results in to malformed request. I am not sure where exactly I am going wrong, any help will would be appreciated. Thanks

2
  • What's the json library? Commented Oct 21, 2016 at 13:01
  • I am using C++ rest SDK and namespace web, I am not using JsonCpp. Commented Oct 21, 2016 at 13:04

1 Answer 1

1

I believe your mistake is that you are constructing a json::value from a json::value::object()

According to the documentation the line should be fixed to:

refRequest[requestKey::Value1] = json::value::object();
Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't refRequest need to be a type object aswell?
No, its not necessary for my case.
Linked documentation is flagged as insecure. If possible this answer needs an updated link or just pasting the documentation in the answer so that it is self contained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.