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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:00:28+00:00 2026-06-16T03:00:28+00:00

I am trying to create the following JSON data: { ‘chart.labels’: [‘Bob’,’Lucy’,’Gary’,’Hoolio’], ‘chart.tooltips’: [‘Bob

  • 0

I am trying to create the following JSON data:

{
'chart.labels': ['Bob','Lucy','Gary','Hoolio'],
'chart.tooltips': ['Bob did well',
               'Lucy had her best result',
               'Gary - not so good',
               'Hoolio had a good start'
              ]
}

I am using C# and trying to create an object in order to do this…..something like:

public class chart{
 public string[] chart.labels {get;set;}
 public string[] chart.tooltips {get;set;}
}

but obviously I cannot have properties containing spaces.

How would I go about doing this ?

UPDATE:

Using JamieC’s answer the following works perfecly

public virtual ActionResult CompanyStatus()
    {
        var labelList = new List<string>() { "Bob", "Lucy", "Gary", "Hoolio" };
        var tooltipsList = new List<string>() { "Bob did well", "Lucy had her best result", "Gary - not so good", "Hoolio had a good start" };

        var cData = new chartData()
        {
            Labels = labelList.ToArray(),
            Tooltips = tooltipsList.ToArray()
        };

        var serializer = new DataContractJsonSerializer(cData.GetType());
        String output;
        using (var ms = new MemoryStream())
        {
            serializer.WriteObject(ms, cData);
            output = Encoding.Default.GetString(ms.ToArray());
        } 

        return this.Content(output);
    }


    [DataContract]
    public class chartData
    {
        [DataMember(Name = "chart.labels")]
        public string[] Labels { get; set; }

        [DataMember(Name = "chart.tooltips")]
        public string[] Tooltips { get; set; }

    }
}

Which produces:

{"chart.labels":["Bob","Lucy","Gary","Hoolio"],"chart.tooltips":["Bob did well","Lucy had her best result","Gary - not so good","Hoolio had a good start"]}
  • 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-16T03:00:30+00:00Added an answer on June 16, 2026 at 3:00 am

    The usual way to do this is to use a DataContractJsonSerializer to turn your object into Json, and use DataMember attributes to annotate what names to use for properties:

    [DataContract]
    public class ChartModel{
     [DataMember(Name = "chart.labels")]
     public string[] Labels {get;set;}
     [DataMember(Name = "chart.tooltips")]
     public string[] Tooltips {get;set;}
    }
    

    I personally use my own ActionResult to wrap up the serialization in MVC:

    public class JsonDataContractResult : ActionResult
    {
        public JsonDataContractResult(Object data)
        {
            this.Data = data;
        }
    
        protected JsonDataContractResult()
        {
    
        }
    
        public Object Data { get; private set; }
    
        public override void ExecuteResult(ControllerContext context)
        {
            Guard.ArgumentNotNull(context, "context");
    
            var serializer = new DataContractJsonSerializer(this.Data.GetType());
            String output; 
            using (var ms = new MemoryStream())
            {
                serializer.WriteObject(ms, this.Data);
                output = Encoding.Default.GetString(ms.ToArray());
            } 
            context.HttpContext.Response.ContentType = "application/json";
            context.HttpContext.Response.Write(output);
        }        
    }
    

    And return that from a helper method in a base controller:

    public abstract class MyBaseController: Controller
    {
    
        protected JsonDataContractResult JsonContract(Object data)
        {
            return new JsonDataContractResult(data);
        }
    
    }
    

    Then my controller becomes really simple:

    public class SomeController: MyBaseController
    {
        public ActionResult SomeAction()
        { 
            var model = new ChartModel()
                       { 
                           Labels = ..., 
                           Tooltips = ... 
                       };
            return JsonContract(model);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a mapping for the following JSON data. { Calls:
Trying to create a list to return some JSON data to a view. Following
I am trying to use use the following JSON data to create the following
Im trying to create an additional function for jqGrid to simplify adding JSON data
I am trying to get the result of the following json webservice https://mtgox.com/code/data/getDepth.php into
I'm trying to create a stacked bar chart with d3 from data in a
I have the following code. I'm trying to create the store via json. I
i'm trying to create following layout: http://jsfiddle.net/BTuMH/1/ but without setting the width, like: http://jsfiddle.net/yuGyg/
i am trying to create an .htaccess file that will achieve the following create
New with Android. Sorry! I'm trying to create the following... Wait for Timer to

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.