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 7072515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:49:05+00:00 2026-05-28T05:49:05+00:00

I was using Json.Net to serialize dictionaries of type Dictionary, and when I added

  • 0

I was using Json.Net to serialize dictionaries of type Dictionary, and when I added integers or booleans to the dictionary, when deserializing I would get integers and booleans back.
Now I was trying to change my code to use ServiceStack.Text instead because of a problem in other part of the code with the serialization of dates, but now I get the booleans an integers as strings after deserialization. Is there any way to have the same behaviour as Json.Net?

Here’s the code to reproduce it: https://gist.github.com/1608951
Test_JsonNet passes, but both Test_ServiceStack_Text_TypeSerializer and Test_ServiceStack_Text_JsonSerializer fail

  • 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-05-28T05:49:06+00:00Added an answer on May 28, 2026 at 5:49 am

    For untyped dynamic payloads it’s better to use the JSON Utils in ServiceStack.Common which lets you parse dynamic payloads whilst preserving their type, e.g:

    var obj = JSON.parse(json);
    if (obj is new Dictionary<string, object> jsonObj) 
    {
        int b = (int)jsonObj["b"];
        bool c = (bool)jsonObj["c"];
    }
    

    It’s a purposeful design decision in ServiceStack.Text JSON Serializer that no type information is emitted for primitive value types which is why the values are left as strings.

    You either have to deserialize into a strong typed POCO that holds the type info:

    public class MixType
    {
        public string a { get; set; }
        public int b { get; set; }
        public bool c{ get; set; }
    }
    
    var mixedMap = new Dictionary<string, object> {
        { "a", "text" },
        { "b", 32 },
        { "c", false },
    };
    
    var json = JsonSerializer.SerializeToString(mixedMap);
    Console.WriteLine("JSON:\n" + json);
    
    var mixedType = json.FromJson<MixType>();
    Assert.AreEqual("text", mixedType.a);
    Assert.AreEqual(32, mixedType.b);
    Assert.AreEqual(false, mixedType.c);
    

    Or deserialize into a Dictionary<string,string> and parse into specific types yourself.

    Or deserialize using ServiceStack’s dynamic API. See ServiceStack’s Dynamic JSON Test folder for examples on how to do this.

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

Sidebar

Related Questions

How would I get my JSON string to my asp.net using jquery I am
It seems impossible to (de-)serialize a generic dictionary using Json.NET out of the box.
I am using Json.NET to serialize an object graph. For each object that is
I'm using JSON.NET implementation to serialize/deserialize .NET objects to JS and vice versa, all
I am trying to serialize a C# object to JSON using JSON.net library. The
I'm using JSON.NET to de-serialize some JSON from a web service. I'm wanting to
I'm fetching JSON from my ASP .NET website using the following jQuery: $.ajax({ type:
I am using ASP.Net to serialize classes designed in C# to JSON. My Javascript
I have a service that attempting to serialize a list into JSON (using JSON.NET)
I have some data that I have to serialize to JSON. I'm using JSON.NET.

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.