.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Reflection;
					
public class Program
{
	public static void Main()
	{
		string input = @"{
    ""predictions"": [
        {
            ""description"": ""Frankfurt am Main, Deutschland"",
            ""place_id"": ""ChIJxZZwR28JvUcRAMawKVBDIgQ"",
        },
        {
            ""description"": ""Frankfurt (Oder), Deutschland"",
            ""place_id"": ""ChIJb_u1AiqYB0cRwDteW0YgIQQ"",
        },
        {
            ""description"": ""Frankfurt Hahn Flughafen (HHN), Lautzenhausen, Deutschland"",
            ""place_id"": ""ChIJX3W0JgQYvkcRWBxGlm6csj0"",
        }
    ],
    ""status"": ""OK""
}";
				
		var objs = JsonConvert.DeserializeObject<ResponseWrapper>(input);
		
		var jsonResolver = new IgnorePropertiesContractResolver();
		// explicity ignore specific property if you really want to
		//jsonResolver.Ignore(typeof(Foo), "string2");
		// ignore single datatype
		//jsonResolver.Ignore(typeof(System.Data.Objects.DataClasses.EntityObject));
		
		var jsonSettings = new JsonSerializerSettings() { 
			ReferenceLoopHandling = ReferenceLoopHandling.Ignore, 
			Formatting = Formatting.Indented,
			NullValueHandling = NullValueHandling.Ignore,
			ContractResolver = jsonResolver 
		};
		
		var output = JsonConvert.SerializeObject(objs, jsonSettings);
		Console.WriteLine(output);
		
	}
	

	public class ResponseWrapper
	{
		[JsonProperty("success")]
		public bool Success { get;set; }
		
		[JsonProperty("message")]
		public string Message { get;set; }
		[Obsolete("This field should not be used anymore, please use Message instead", true)]
		public string Status 
		{ 
			get { return Message; }
			set 
			{ 
				Message = value; 
				Success = value.Equals("OK", StringComparison.OrdinalIgnoreCase);
			}
		}
		
		[JsonProperty("data")]
		public Prediction[] Data { get;set; }
		[Obsolete("This field should not be used anymore, please use Data instead", true)]
		public Prediction[] Predictions 
		{ 
			get { return Data; } 
			set { Data = value; }
		}
	}
	public class Prediction
    {
        public string description { get; set; }
        public string place_id { get; set; }
    }
	
	/// <summary>
	/// Special JsonConvert resolver that allows you to ignore Obsolete and explicitly defined properties.
	/// </summary>
	/// <remarks>  See https : //stackoverflow.com/a/13588192/1037948</remarks>
	public class IgnorePropertiesContractResolver : DefaultContractResolver 
	{
		protected readonly Dictionary<Type, HashSet<string>> Ignores;

		public IgnorePropertiesContractResolver() 
		{
        	this.Ignores = new Dictionary<Type, HashSet<string>>();
			this.IgnoreObsoleteProperties = true;
    	}

		/// <summary>Ignore Obsolete Properties automatically</summary>
		/// <remarks>This uses reflection and may add an undesirable performance overhead for large object graphs or many serializations</remark>
		[DefaultValue(true)]
		public bool IgnoreObsoleteProperties { get;set; }
		
		/// <summary>
		/// Explicitly ignore the given property(s) for the given type
		/// </summary>
		/// <param name="type"></param>
		/// <param name="propertyName">one or more properties to ignore.  Leave empty to ignore the type entirely.</param>
		public void Ignore(Type type, params string[] propertyName) {
			// start bucket if DNE
			if (!this.Ignores.ContainsKey(type)) this.Ignores[type] = new HashSet<string>();

			foreach (var prop in propertyName) {
				this.Ignores[type].Add(prop);
			}
		}

		/// <summary>
		/// Is the given property for the given type ignored?
		/// </summary>
		/// <param name="type"></param>
		/// <param name="propertyName"></param>
		/// <returns></returns>
		public bool IsIgnored(Type type, string propertyName) {
			
			if (IgnoreObsoleteProperties)
			{
				var prop = type.GetProperty(propertyName);
				if (prop != null && prop.GetCustomAttributes(typeof(ObsoleteAttribute), false).Any())
				return true;
			}
			
			if (!this.Ignores.ContainsKey(type)) return false;

			// if no properties provided, ignore the type entirely
			if (this.Ignores[type].Count == 0) return true;

			return this.Ignores[type].Contains(propertyName);
		}

    /// <summary>
    /// The decision logic goes here
    /// </summary>
    /// <param name="member"></param>
    /// <param name="memberSerialization"></param>
    /// <returns></returns>
    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) {
        JsonProperty property = base.CreateProperty(member, memberSerialization);

        if (this.IsIgnored(property.DeclaringType, property.PropertyName)) {
            property.ShouldSerialize = instance => { return false; };
        }

        return property;
    }
}
}
;