using Newtonsoft.Json.Linq;
public static void Main()
Test(JObject.Parse("{\"body\":\"eyJ0ZXN0IjoiYm9keSJ9\",\"resource\":\"/{proxy+}\",\"path\":\"/path/to/resource\",\"httpMethod\":\"GET\",\"isBase64Encoded\":true,\"queryStringParameters\":{\"foo\":\"bar\"},\"multiValueQueryStringParameters\":{\"foo\":[\"bar\"]},\"pathParameters\":{\"proxy\":\"/path/to/resource\"},\"stageVariables\":{\"baz\":\"qux\"}}"));
private static void Test(JObject request)
Console.WriteLine("Log: request: " + request.ToString());
if (request["pathParameters"]["proxy"] != null)
unit_id = request["pathParameters"]["proxy"].ToString();
Console.WriteLine("Log: Get request.PathParameters - unit_id: " + unit_id.ToString());
public static class JsonHelper
public static bool IsNullOrEmpty(this JToken token)
return (token == null) ||
(token.Type == JTokenType.Array && !token.HasValues) ||
(token.Type == JTokenType.Object && !token.HasValues) ||
(token.Type == JTokenType.String && token.ToString() == String.Empty) ||
(token.Type == JTokenType.Null);
public static bool IsNullOrEmpty2(this JToken token)
return token == null || string.IsNullOrWhiteSpace(token.ToString());