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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:52:42+00:00 2026-05-24T13:52:42+00:00

How do I skip out certain properties when converting my object to json through

  • 0

How do I skip out certain properties when converting my object to json through the controller’s method?

public JsonResult GetPerson(int PersonId)
{
    Person thisPerson = Person.GetById(PersonId);
    return Json(thisPerson); //Please strip SecretAlterEgoName from your results please!
}

class Person
{
    int PersonId { get; set; }
    string Name { get; set; }
    string SecretAlterEgoName { get; set; } //Must not send this! No on must know!
}

And I want to avoid this:
{“PersonId”:3,”Name”:”Peter Parker”,”SecretAlterEgoName”:”Spiderman”}

and instead show this:
{“PersonId”:3,”Name”:”Peter Parker”}

I was hoping to avoid having to use StringBuilder to generate my json string, and avoid creating a new object with less properties to transfer to.

  • 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-24T13:52:43+00:00Added an answer on May 24, 2026 at 1:52 pm

    I’m reasonably sure — but can’t test right now — that you can generate the JSON from an anonymous type, and only include the fields that you’re interested in when you create the type:

    public JsonResult GetPerson(int PersonId)
    {
        Person thisPerson = Person.GetById(PersonId);
        return Json(new { thisPerson.PersonId, thisPerson.Name });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes you need to skip execution of part of a method under certain non-critical
How do I skip over this next line if it turns out to be
Is there a easy way to skip the readLine() method in java if it
I am trying to figure out a way to skip the next two lines
Busy on a project and I need to skip the shipping method step. Shop
I'm trying to figure out how to skip printing a row from a MySQL
SKIP TO UPDATE 3 I want to enable the Seam debug page on Weblogic
Skip to the specific question as needed. Some background: The scenario: I have a
I want to skip to the first line that contains include. <> until /include/;
Is it possible to skip a couple of characters in a capture group in

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.