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

  • Home
  • SEARCH
  • 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 8080041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:18:02+00:00 2026-06-05T16:18:02+00:00

I have a class like so: [JsonObject(MemberSerialization.OptIn)] public class foo { [JsonProperty(name_in_json)] public string

  • 0

I have a class like so:

[JsonObject(MemberSerialization.OptIn)]
public class foo
{
     [JsonProperty("name_in_json")]
     public string Bar { get; set; }
     // etc. 
     public Dictionary<string, bool> ImageFlags { get; set; }
}

The JSON is generated from a CSV file originally, each line representing a foo object – it’s basically flat, so I need to map certain keys to imageflags.

I tried to write a CustomCreationConverter based on the example here.

This seems to map the flags fine, but it fails setting normal properties – it looks for ‘bar’ instead of ‘name_in_json’.

How would I go about getting ‘name_in_json’ value for an object of type foo?

edit:

current solution:

 var custAttrs = objectType.GetProperties().Select(p =>     p.GetCustomAttributes(typeof(JsonPropertyAttribute), true)).ToArray();
 var propNames = objectType.GetProperties().Select(p => p.Name.ToLower()).ToArray();
 Dictionary<string, string> objProps = new Dictionary<string, string>();
 for (int i = 0; i < propNames.Length; i++) 
     // not every property has json equivalent...
     if (0 == custAttrs[i].Length)
     {
         continue;
     }

     var attr = custAttrs[i][0] as JsonPropertyAttribute; 
     objProps.Add(attr.PropertyName.ToLower(), propNames[i].ToLower());
 }
  • 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-05T16:18:05+00:00Added an answer on June 5, 2026 at 4:18 pm

    Okay, in the example above you get all property names from type with:

    var objProps = objectType.GetProperties().Select(p => p.Name.ToLower()).ToArray();
    

    So you use only actual property name, what youshould do instead is for each property get custom attribute of type JsonProperty using GetCustomAttributes method, and get json property name from it.

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

Sidebar

Related Questions

I have a class like this, public class person { name Name {set; get;}
I have a class like this public class foo { private void getThread() {
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
Let's say I have this object: [JsonObject] public class User { [JsonProperty(PropertyName = id)]
I have class like this: public class Class1 { private String result; private String
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
I have a class like so: public abstract class ClassA<T> { protected ClassA(IInterface interface)
I have a class like this class GUI : public QWidget, public QThread When
i have a class like [Serializable] public class MyClass { [XmlAttribute] public bool myBool
I have a simple class in asp.net mvc that looks like this: public class

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.