I have the following code
class MyJSONSerializableClass
{
[JsonProperty("index")]
public int Index { get; set; };
[JsonIgnore]
public long Id { get; set; };
}
var collection = new List<MyJSONSerializableClass>()
{
new MyJSONSerializableClass()
{
Index = 10,
Id = 1000
}
};
string jsonOutput = JsonConvert.SerializeObject(collection);
jsonOutput would be
[{ index: 10 }]
I would like jsonOutput to be
[ 10 ]
Is there any class attribute I can apply to MyJSONSerializableClass that would tell JSON.NET to emit only the property Index, instead of the entire object?
Something along the lines of
[JsonOutput(f => f.Index)]
class MyJSONSerializableClass
{
...
}
Thanks
Not sure about the attributes, but alternatively, you could try
As per documentation, all IEnumerable’s will be arrays.