예제 #1
0
        public void JsonPathSetNewSecondLevelValue()
        {
            string modifiedJson = JsonPath.SetValueForJsonPath(this.GetJson(), "$.zippy.foo", "do-dah");

            dynamic result = JsonConvert.DeserializeObject(modifiedJson);

            Assert.AreEqual(JsonPath.ConvertValueForOutput(result.zippy.foo), "do-dah");
        }
예제 #2
0
        public void JsonPathSetArrayValue()
        {
            string modifiedJson = JsonPath.SetValueForJsonPath(this.GetJson(), "$.children[0].name", "something-else-completely");

            dynamic result = JsonConvert.DeserializeObject(modifiedJson);

            Assert.AreEqual(JsonPath.ConvertValueForOutput(result.children[0].name), "something-else-completely");
        }
예제 #3
0
        public void JsonPathSetSecondLevelValue()
        {
            string modifiedJson = JsonPath.SetValueForJsonPath(this.GetJson(), "$.another.value", "something-else-completely");

            dynamic result = JsonConvert.DeserializeObject(modifiedJson);

            Assert.AreEqual(JsonPath.ConvertValueForOutput(result.another.value), "something-else-completely");
        }
예제 #4
0
        public void JsonPathSetTopLevelValue()
        {
            string modifiedJson = JsonPath.SetValueForJsonPath(this.GetJson(), "$.id", "5678");

            dynamic result = JsonConvert.DeserializeObject(modifiedJson);

            Assert.AreEqual(JsonPath.ConvertValueForOutput(result.id), "5678");
        }
예제 #5
0
        public void JsonPathComplexTypeName()
        {
            string json = "{ \"name\": \"foobar\" }";

            string  modifiedJson = JsonPath.SetValueForJsonPath(json, "$.['@name.conflictBehavior']", "replace");
            dynamic result       = JsonConvert.DeserializeObject(modifiedJson);

            Assert.AreEqual(JsonPath.ConvertValueForOutput(result["@name.conflictBehavior"]), "replace");
        }
예제 #6
0
        internal static string RewriteJsonBodyWithParameters(string jsonSource, IEnumerable <PlaceholderValue> parameters)
        {
            if (string.IsNullOrEmpty(jsonSource))
            {
                return(jsonSource);
            }

            var jsonParameters = (from p in parameters
                                  where p.Location == PlaceholderLocation.Json
                                  select p);


            foreach (var parameter in jsonParameters)
            {
                jsonSource = JsonPath.SetValueForJsonPath(jsonSource, parameter.PlaceholderKey, parameter.Value);
            }

            return(jsonSource);
        }