Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:59:04+00:00 2026-06-17T18:59:04+00:00

I am using json.net(newtonsoft) and I want to build a json request but I

  • 0

I am using json.net(newtonsoft) and I want to build a json request but I have 2 different dictionaries and not sure how to join them.

   Dictionary<string, HttpStatusCode> code = new Dictionary<string, HttpStatusCode>();
   code.Add("Message", statusCode);

Dictionary<string, IErrorInfo> modelState = new Dictionary<string, IErrorInfo>();
// some code to add to this modelState

Edit

IErrorInfo just has some properties

public interface IErrorInfo
    {
        SeverityType SeverityType { get; set; }
        ValidationType ValidationType { get; set; }
        string Msg { get; set; }
    }

The result I trying to go for is something like this

{
  "Message": 400, // want this to be text but not sure how to do that yet (see below)
  "DbError":{
        "SeverityType":3,
        "ValidationType":2,
        "Msg":"A database error has occurred please try again."
        }
}

I am basically trying to achieve this.

HttpError and Model Validation

For model validation, you can pass the model state to CreateErrorResponse, to include the validation errors in the response:

public HttpResponseMessage PostProduct(Product item)
{
    if (!ModelState.IsValid)
    {
        return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
    }

    // Implementation not shown...
}

This example might return the following response:

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Content-Length: 320

{
  "Message": "The request is invalid.",
  "ModelState": {
    "item": [
      "Required property 'Name' not found in JSON. Path '', line 1, position 14."
    ],
    "item.Name": [
      "The Name field is required."
    ],
    "item.Price": [
      "The field Price must be between 0 and 999."
    ]
  }
}

The reason why I am not using this built in method is because I have a separate built in class library that has all my business logic in it. I want to keep it so that it has no dependency on web stuff or mvc stuff(like modelState).

This is why I created my own sort of model state with a bit of extra stuff in it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:59:06+00:00Added an answer on June 17, 2026 at 6:59 pm

    You should be able to just use one Dictionary and add items from both of your dictionaries into this dictionary. Json.NET should serialize it all like you’re expecting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working application using Json.NET (newtonsoft) as a custom serializer. Currently I'm
I am using Newtonsoft's JSON.NET library to serialize some objects. In particular, I want
I have just started using Newtonsoft.Json (Json.net). In my first simple test, I ran
I'm using Newtonsoft JSON.NET 4.5r7 in an MVC4 non-api project. Below I rename id
Currently I am using the terrific Linq 2 Json.net (by newtonsoft), which is a
I am using json.net to parse objects and delivering them to a webservice I
I have some data that I have to serialize to JSON. I'm using JSON.NET.
I'm trying to create two method to serialize/deserialize classes using Json.Net and save/load them
I am currently using Json.Net to deserialize my JSON. I now have the following
I am using NewtonSoft Json.NET library for parsing JSON files in a .NET app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.