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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:42:38+00:00 2026-05-10T17:42:38+00:00

Since Object Initializers are very similar to JSON, and now there are Anonymous Types

  • 0

Since Object Initializers are very similar to JSON, and now there are Anonymous Types in .NET. It would be cool to be able to take a string, such as JSON, and create an Anonymous Object that represents the JSON string.

Use Object Initializers to create an Anonymous Type:

var person = new {     FirstName = 'Chris',     LastName = 'Johnson' }; 

It would be awesome if you could pass in a string representation of the Object Initializer code (preferably something like JSON) to create an instance of an Anonymous Type with that data.

I don’t know if it’s possible, since C# isn’t dynamic, and the compiler actually converts the Object Initializer and Anonymous Type into strongly typed code that can run. This is explained in this article.

Maybe functionality to take JSON and create a key/value Dictionary with it would work best.

I know you can serialize/deserializer an object to JSON in .NET, but what I’m look for is a way to create an object that is essentially loosely typed, similarly to how JavaScript works.

Does anyone know the best solution for doing this in .NET?

UPDATE: Too clarify the context of why I’m asking this… I was thinking of how C# could better support JSON at the language level (possibly) and I was trying to think of ways that it could be done today, for conceptual reasons. So, I thought I’d post it here to start a discussion.

  • 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. 2026-05-10T17:42:38+00:00Added an answer on May 10, 2026 at 5:42 pm

    There are languages for .NET that have duck-typing but it’s not possible with C# using Dot.Notation since C# requires that all member references are resolved at compile time. If you want to use the Dot.Notation, you still have to define a class somewhere with the required properties, and use whatever method you want to instantiate the class from the JSON data. Pre-defining a class does have benefits like strong typing, IDE support including intellisense, and not worrying about spelling mistakes. You can still use anonymous types:

     T deserialize<T>(string jsonStr, T obj) { /* ... */}   var jsonString = '{FirstName='Chris', LastName='Johnson, Other='unused'}';  var person     = deserialize(jsonString, new {FirstName='',LastName=''});  var x          = person.FirstName; //strongly-typed 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since there is no way that you can make the flash object transparent, there
since method Add() takes Object as an argument, can I add for example datatables,
Since http is stateless, every request to an app creates a new object. How
Java's Properties object hasn't changed much since pre-Java 5, and it hasn't got Generics
I want a Python object that will monitor whether other objects have changed since
I cannot run ['abc'].append( MyModel.objects.all() ) since it generates exception 'NoneType' object is not
How to instantiate a derived class object, whose base class ctor is private? Since
I recently noticed the CallByName keyword in VB6. Since this takes a object, procedure
String s; /*code*/ s = foo; Is a whole new object being created, since
Since HashMap and HashSet allows null objects, what would be the hash value of

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.