How to dynamically create DataTable columns from JSON keys in UiPath C#?

Hi @Vhierdy_Hafidz

Select C Sharp in Properties Panel of Invoke Code:

Try the below Invoke Code:

// Input: jsonResponse (string) - your JSON input
// Output: outputTable (DataTable) - your dynamically built DataTable

var nameObj = jObj["results"]?[0]?["name"] as JObject;

outputTable = new DataTable();

if (nameObj != null)
{
    // Create columns dynamically based on name object keys
    foreach (var prop in nameObj.Properties())
    {
        outputTable.Columns.Add(prop.Name, typeof(string));
    }

    // Create a new row and fill values
    var newRow = outputTable.NewRow();
    foreach (var prop in nameObj.Properties())
    {
        newRow[prop.Name] = prop.Value?.ToString();
    }
    outputTable.Rows.Add(newRow);
}

Invoke Code Arguments:

You can remove the entire Multiple Assign activity and try the above code.

Hope it helps!!