protected override void Add(AddOperation operation) { var token = operation.Path.Find(_target, skipLast: true); int index; if (int.TryParse(operation.Path.Last, out index)) ((JArray)token).Insert(index, operation.Value); else if (operation.Path.Last == "-") ((JArray)token).Add(operation.Value); else token[operation.Path.Last] = operation.Value; }
protected override void Add(AddOperation operation) { JToken token = null; JObject parenttoken = null; try { if (operation.Path.IsNewPointer()) { var parentPointer = operation.Path.ParentPointer; token = parentPointer.Find(_target) as JArray; } else { token = operation.Path.Find(_target); } } catch (ArgumentException) { var parentPointer = operation.Path.ParentPointer; parenttoken = parentPointer.Find(_target) as JObject; } if (token == null && parenttoken != null) { parenttoken.Add(operation.Path.ToString().Split('/').Last(), operation.Value); } else if (token is JArray) { var array = token as JArray; array.Add(operation.Value); } else if (token.Parent is JProperty) { var prop = token.Parent as JProperty; prop.Value = operation.Value; } }