Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
How to deserialize JSON with properties named "1" and "2"? These aren't valid property names in C#

I am calling a REST API from C# where the class name is a number, which isn't allowed in C#. I'm not sure how I can get around this? I'm using Newtonsoft for the serialization.

This is the JSON from my REST API:

{
  "customfield_10323": {
    "1": [
      "com.atlassian.greenhopper.service.sprint.Sprint@2442b4ee[id=78,rapidViewId=21,state=CLOSED,name=APPLE A5 (27/07 - 07/08),startDate=2020-07-27T08:00:00.000+01:00,endDate=2020-08-07T17:00:00.000+01:00,completeDate=2020-08-13T11:22:53.314+01:00,sequence=78,goal=]",
      "com.atlassian.greenhopper.service.sprint.Sprint@54cfb92f[id=107,rapidViewId=19,state=ACTIVE,name=ORANGE B2 (08/03 - 19/03),startDate=2021-03-08T08:00:00.000Z,endDate=2021-03-19T17:00:00.000Z,completeDate=<null>,sequence=107,goal=]"
    ],
    "2": [
      {
        "id": 78,
        "name": "APPLE A5 (27/07 - 07/08)",
        "state": "closed",
        "boardId": 21
      },
      {
        "id": 107,
        "name": "ORANGE B2 (08/03 - 19/03)",
        "state": "active",
        "boardId": 19
      }
    ]
  }
}

Which I've translated to this:

public class 2
{
    public int id { get; set; }
    public string name { get; set; }
    public string state { get; set; }
    public int boardId { get; set; }
}

public class Customfield10323
{
    public List<string> _1 { get; set; }
    public List<2> 2 { get; set; }
}

public class Root
{
    public Customfield10323 customfield_10323 { get; set; }
}

But I'm not sure this is correct because I can't call the class 2 because it violates naming conventions. Any help would be appreciated as I'm really stuck!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Modify your classes to use the JsonProperty attribute:

public class Two // valid class name
{
    public int id { get; set; }
    public string name { get; set; }
    public string state { get; set; }
    public int boardId { get; set; }
}

public class Customfield10323
{
    [JsonProperty("1")] // property name in JSON
    public List<string> One { get; set; } // valid property name

    [JsonProperty("2")] // property name in JSON
    public List<Two> Two { get; set; } // valid property name
}

public class Root
{
    public Customfield10323 customfield_10323 { get; set; }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!