0

Hi I have below method which I calling in and that generates two string value(Partition Key and Row key). and My json do not have these two keys, so I would like to add these two values in my existing Json.

I need help in modifying my code below to add these two keys and values:

internal async Task<(string, string)> GenerateKeys( Dictionary<string, EntityProperty> arg )
{            
    var result = await GenerateValuesFromScript( arg, sbForKeyColumns );
    return (result.First().ToString(), result.Last().ToString());
}

var content = JsonConvert.DeserializeObject<JObject>( lines );
   
await GenerateKeys( jsonDictionary );// above method is called and two values are returned
content.Add( new JProperty( "PartitionKey", "//this is where I have to pass the above 1st values" ) );
content.Add( new JProperty( "RowKey", "//this is where I have to pass the above 2nd values" ) );
ZZZSharePoint
  • 1,163
  • 1
  • 19
  • 54

1 Answers1

1

You need to assign the result of GenerateKeys to a variable. Since GenerateKeys returns a tuple, you can simply reference each of the entries via Item1, Item2 etc, syntax, adding the properties to your JObject.

var lines = "{\"id\": 1}";

var content = JsonConvert.DeserializeObject<JObject>(lines);
var keys = await GenerateKeys();// above method is called and two values are returned
content.Add(new JProperty("PartitionKey", keys.Item1));
content.Add(new JProperty("RowKey", keys.Item2));
    

// This is a very simplistic example of your method since I can't reproduce your params
internal async Task<(string, string)> GenerateKeys()
{
    return await Task.FromResult(("PartitionKeyValue", "RowKeyValue"));
}

This results in the following JSON:

{
  "id": 1,
  "PartitionKey": "PartitionKey",
  "RowKey": "RowKey"
}
David L
  • 32,885
  • 8
  • 62
  • 93
  • row key come like this rowkey: [\r\n 0,\r\n 12,\r\n 0\r\n]XTTJF012.any way to fix this while actually the value is [0,12,0]XTTF012 – ZZZSharePoint Jun 16 '21 at 13:36
  • Are you going to have consistent types in each position? That’s just addition carriage return data that you could trim if you treat every data point as a string. – David L Jun 16 '21 at 13:41