After searching around for a while I found a solution allowing you to send through a JSON object in a post request of a web test.
1) Create a web test performance plugin: https://learn.microsoft.com/en-us/visualstudio/test/how-to-create-a-web-performance-test-plug-in?view=vs-2017
2) Add the following code into the class (don't forget to build):
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace WebTests.RequestPlugins
{
[DisplayName("Add JSON content to Body")]
[Description("HEY! Tip! Uglify your JSON before pasting.")]
public class AddJsonContentToBody : WebTestRequestPlugin
{
[Description("Assigns the HTTP Body payload to the content provided and sets the content type to application/json")]
public string JsonContent { get; set; }
public override void PreRequest(object sender, PreRequestEventArgs e)
{
var stringBody = new StringHttpBody();
stringBody.BodyString = JsonContent;
stringBody.ContentType = "application/json";
e.Request.Body = stringBody;
}
}
3) On your request URL r-click and select 'Add Request Plugin' then you should see your new plugin.
4) Uglify your json to be able to paste.
5) Run test
Source to code: https://ericflemingblog.wordpress.com/2016/01/21/helpful-custom-request-plugins-for-web-tests/