JSOn Serializing PageData


I am trying to serialize a PageData object into Json.
JsonConvert.SerializeObject(Model,Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore,NullValueHandling = NullValueHandling.Ignore }))

I am getting infinite loops until my server runs out of memory. My page has block data on them.

Is there another approach to this?

Feb 11, 2014 15:41

Hi Oliver,

As I am not sure what exactly you are trying to accomplish, so just a link to a post a wrote while back. It might do or help you do what you are trying to accomplish.



Edited, Feb 11, 2014 16:41

If you don't need/want the blockdata in your JSON output you might also add a [JsonIgnore] attribute to your ContentArea? And all properties you do not want in your output. But as I said, I am not sure what exactly you are trying to accomplish, so I am not sure if I'm answering your question.

Feb 11, 2014 17:08

I am using handbars as template framework, and I need to json-serialize my episerver page properties.

Feb 11, 2014 19:02

So you need to json-serialize only properties that need displaying, correct? I think you'd best try to add the [JsonIgnore] attribute to all properties that you don't use for display.

Additionally, if you have rich text properties, you might want to check if the html in them gets "javascript encoded" when it gets converted to json.

Feb 11, 2014 20:05

This was my workaround... Makes a non-chokable structure for Json serializing...

        /// <summary>
        /// This method converts a PageData into  Dictionary objects. This methods is convinient when the serializer chokes on a PageData
        /// </summary>
        /// <param name="content"></param>
        /// <param name="result"></param>
        /// <returns>A key/value dictionary</returns>
        public Dictionary<string, object> GetAllContentProperties(IContentData content, Dictionary<string, object> result)
            foreach (var prop in content.Property)
                if (prop.GetType().IsGenericType &&
                    prop.GetType().GetGenericTypeDefinition() == typeof (PropertyBlock<>))
                    var newStruct = new Dictionary<string, object>();
                    GetAllContentProperties((IContentData)prop, newStruct);
                if(prop.Value != null)

            return result;


Feb 12, 2014 10:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.