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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:16:12+00:00 2026-06-02T16:16:12+00:00

Is there a way to conditionally exclude items from JSON serialization? I’m using C#

  • 0

Is there a way to conditionally exclude items from JSON serialization? I’m using C# in a .NET4 application with WebAPI. I have [DataMember] and [ScriptIgnore] already on my classes and everything works fine. What I want to do is not include certain properties at runtime based on the property’s value

For instance, I may only want to serialize List<Foo> myFoo when

myFoo != null && myFoo.Count > 0

The JSON is translated back into my own JS objects on the client, which will have all properties instantiated already like myFoo: []. It’s just unnecessary to send these in JSON to the client as it essentially will have no effect on the object and only is sending more data and using more processing on the client. It’s a very JS heavy HTML5 mobile site and I’m trying to reduce as much data and processing as I can.

  • 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-02T16:16:14+00:00Added an answer on June 2, 2026 at 4:16 pm

    I found Json.net which will allow me to do conditional serialization at runtime.

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

Sidebar

Related Questions

What the easiest/right way to conditionally exclude a java file from compilation in a
Is there a way in Delphi 2009 to have a section of code conditionally
Is there a way to conditionally embed resources into a .NET project? I.e. if
I was wondering if there is a way to conditionally compile entire namespaces in
Is there any way to do something conditionally in jquery only if IE6 is
Is there a way to dynamically and conditionally create a class definition in PHP,
is there way how to get name ov event from Lambda expression like with
Is there any way I can conditionally compile in my app based upon whether
Is there a built-in asp.net way to conditionally serve pages, for example I want
Is there a way to conditionally pass a value into this statement? OUTER APPLY

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.