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

The Archive Base Latest Questions

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

Here is the basic nature of what i’m doing. Note: this is pseudocode.. this

  • 0

Here is the basic nature of what i’m doing. Note: this is pseudocode.. this code is from memory, and I don’t have intellisense to bark at me about syntax! 🙂

(Description after the code)

Controller:

{
    public JSONResult GetCalendar(Form){
        var data = Workshops.Select().ToEventViews();
        var moreData = Appointments.Select().ToEventViews();

        data.AddRange(moreData);

        return Json(data);

    }
}

ViewModel
{
    public class EventView{
        string prop1;
        string prop2;
        string prop3;
        string prop4;
        string prop5;
    }
}

BLL 
{
    public EventView ToEventView(Workshop w){
        return new EventView{
            prop1 = w.thing;
            prop2 = w.thing2;
        //props 3, 4 and 5 not needed
        }
    }

    public EventView ToEventView(Appointment a){
        return new EventView{
            prop1 = a.thing;
            prop2 = a.thing;
            prop3 = a.thing;
            prop5 = a.thing;
        }
    }

    public List<EventView> ToEventView(List<Workshop> wshops){
        return wshops.ConvertAll(w=> w.ToEventView().ToList());
    }

    public List<EventView> ToEventView(List<Appointment> appts){
        return appts.ConvertAll(a=> a.ToEventView().ToList());
    }

}

I’m developing an AJAX calendar app. As you can see, I”m getting a list of workshops and appointments, which have a lot in common (property-wise). There are actually 20+ properties in the EventView class. Thus, I’ve made a ViewModel that holds the properties I need serialized, many of which are common to both appointments and workshops. This is really helpful on the JS side of things, as my app is agnostic about whether each event is an appointment or workshop.

While Appointments and Workshops have a lot in common, they don’t use the exact same set of properties in EventView (notice Appointment just uses prop1 and prop2, while Appointment uses prop1, prop2, prop3 and prop5).

Currently, I’m sending back 200KB of JSON as a result of this request. Sadly, probably 25% of this is fluff from the properties that are serialized but not used — sending back an workshop serialized as {prop1='value', prop2='value', prop3='', prop4='', prop5=''}.

So here’s the question: When I return Json(data) in the controller, is there a way to iterate through all the serialized data and remove all properties that have no value? Essentially I’d like to write a method that accomplishes this: json(data).RemoveEmptyProperties();

Thoughts?

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

    Using the travers library (https://github.com/substack/js-traverse), something like this will remove all empty nodes:

    var traverse = require('traverse');
    
    traverse(data).forEach(function (x) {
        var bUpdate = false;
        for( var key in x )
        { 
          if( "" === x[key] )
          {
            delete x[key];
            bUpdate = true;
          }
        if( bUpdate )this.update(x + 128);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a commit of this app up here The basic problem is, in
Here is my basic use case: After Labview receives a trigger from external hardware
I might be missing something basic here, but I'm stumped on this error: model
I'm trying to do something very basic here, something I wouldn't have expected to
Sorry if this is generic in nature, but I have a question that maybe
I am sure I am overlooking something very basic here, but I just don't
So I am working on Note Onset Detection. I have implemented the method here:
Overlooking something basic here but I am trying to set a variable and have
Something really basic here I fear. Have three sliders used to control the colour
I'm new to windows services, so pardon the basic nature of this post. I've

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.