1

I'm using Newtonsoft and I have this JSON property:

[JsonProperty("br")]
public Market Market { get; set; }

But I want to set the name of the property as a variable, like this:

string market = TestContext.Parameters["market"];
[JsonProperty(market)]
public Market Market { get; set; }

There is any way to do it?

sergiomap
  • 11
  • 2

1 Answers1

0

You can simply use PropertyName in JSON

[JsonProperty(PropertyName = "market")]
public Market Market { get; set; }
Harsha W
  • 3,162
  • 5
  • 43
  • 77
  • but market will have different names that I pass as a parameter. TestContext.Parameters["market"] could return "br", "ar", "es", ... – sergiomap Feb 16 '18 at 10:27
  • Try this link : https://stackoverflow.com/questions/44433732/dynamically-change-the-json-property-name-and-serialize – Harsha W Feb 16 '18 at 10:29