<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace JsonConfig
{
    public static class JsonNetAdapter
    {
        public static ExpandoObject Transform(ExpandoObject data)
        {
            var newExpando = new ExpandoObject();

            var edict = (IDictionary<string, object>)newExpando;

            foreach (var kvp in data)
            {
                if (kvp.Value is ExpandoObject)
                {
                    edict[kvp.Key] = Transform((ExpandoObject)kvp.Value);
                }
                else if (kvp.Value is List<object>)
                {
                    var result = ConvertList((List<object>)kvp.Value);

                    if (result.GetType().GetElementType() == typeof(ExpandoObject))
                    {
                        var expandoArray = (ExpandoObject[])result;

                        for (var i = 0; i < expandoArray.Length; i++)
                        {
                            expandoArray[i] = Transform(expandoArray[i]);
                        }
                    }

                    edict[kvp.Key] = result;
                }
                else
                {
                    edict[kvp.Key] = kvp.Value;
                }
            }

            return newExpando;
        }

        private static object ConvertList(List<object> list)
        {
            var hasSingleType = true;

            ArrayList tList = new ArrayList(list.Count);

            Type listType = null;

            if (list.Count > 0)
            {
                listType = list.First().GetType();
            }

            foreach (var v in list)
            {
                hasSingleType = hasSingleType && listType == v.GetType();
                tList.Add(v);
            }

            return tList.ToArray(hasSingleType && listType != null ? listType : typeof(object));
        }
    }
}<commit_msg>Fixed a bug that might happen when a list has nested lists<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace JsonConfig
{
    public static class JsonNetAdapter
    {
        public static ExpandoObject Transform(ExpandoObject data)
        {
            var newExpando = new ExpandoObject();

            var edict = (IDictionary<string, object>)newExpando;

            foreach (var kvp in data)
            {
                edict[kvp.Key] = TransformByType(kvp.Value);
            }

            return newExpando;
        }

        private static object TransformByType(object value)
        {
            if (value is ExpandoObject)
            {
                return Transform((ExpandoObject)value);
            }

            if (value is List<object>)
            {
                return ConvertList((List<object>)value);
            }

            return value;
        }

        private static object ConvertList(List<object> list)
        {
            var hasSingleType = true;

            ArrayList tList = new ArrayList(list.Count);

            Type listType = null;

            if (list.Count > 0)
            {
                listType = list.First().GetType();
            }

            foreach (var v in list)
            {
                hasSingleType = hasSingleType && listType == v.GetType();
                tList.Add(TransformByType(v));
            }

            return tList.ToArray(hasSingleType && listType != null ? listType : typeof(object));
        }
    }
}
{'fraction_non_alphanumeric': 0.08749298934380258, 'fraction_numerical': 0.0008412787436904094, 'mean_word_length': 1.349802371541502, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3488318', 'n_tokens_mistral': 934, 'n_tokens_neox': 871, 'n_words': 210}