<commit_before>//
//  JSON.swift
//  ArrowExample
//
//  Created by <NAME> on 14/04/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public class JSON:AnyObject, CustomDebugStringConvertible { //Struct??
    
    public func dateFormat(format:String) -> Self {
        jsonDateFormat = format
        return self
    }
    
    public var jsonDateFormat:String?
    
    public var data:AnyObject?
    
    public init?(_ dic:AnyObject?) {
        if dic == nil {
            return nil
        } else {
            data = dic
        }
    }
    
    public var debugDescription: String {
        return data!.debugDescription
    }
    
    public subscript(key: String) -> JSON? {
        get {
            let keys =  key.characters.split{$0 == "."}
            if keys.count > 1 { // KeyPath parsing
                let keysArray:[String] =  keys.map(String.init)
                if var intermediateValue = JSON(data) {
                    for k in keysArray {
                        if let value = intermediateValue[k] {
                            intermediateValue = value
                        } else {
                            return nil
                        }
                    }
                    return intermediateValue
                }
            } else { // Regular parsing
                if let d = data, x = d[key], subJSON = JSON(x) {
                    return subJSON
                }
            }
            return nil
        }
        set(obj) {
            if var d = data as? [String:AnyObject] {
                d[key] = obj
            }
        }
    }
    
    public subscript(index: Int) -> JSON? {
        get {
            if let array = data as? [AnyObject] where array.count > index {
                return JSON(array[index])
            } else {
                return nil
            }
        }
    }

}<commit_msg>Adds collection handy helper for getting Json Array<commit_after>//
//  JSON.swift
//  ArrowExample
//
//  Created by <NAME> on 14/04/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

public class JSON:AnyObject, CustomDebugStringConvertible { //Struct??
    
    public var data:AnyObject?
    public var jsonDateFormat:String?
    
    public init?(_ dic:AnyObject?) {
        if dic == nil {
            return nil
        } else {
            data = dic
        }
    }
    
    var collection:[JSON]? {
        if let a = data as? [AnyObject] {
            return a.map{ JSON($0)! }
        } else {
            return nil
        }
    }
    
    public func dateFormat(format:String) -> Self {
        jsonDateFormat = format
        return self
    }
    
    public var debugDescription: String {
        return data!.debugDescription
    }
    
    public subscript(key: String) -> JSON? {
        get {
            let keys =  key.characters.split{$0 == "."}
            if keys.count > 1 { // KeyPath parsing
                let keysArray:[String] =  keys.map(String.init)
                if var intermediateValue = JSON(data) {
                    for k in keysArray {
                        if let value = intermediateValue[k] {
                            intermediateValue = value
                        } else {
                            return nil
                        }
                    }
                    return intermediateValue
                }
            } else { // Regular parsing
                if let d = data, x = d[key], subJSON = JSON(x) {
                    return subJSON
                }
            }
            return nil
        }
        set(obj) {
            if var d = data as? [String:AnyObject] {
                d[key] = obj
            }
        }
    }
    
    public subscript(index: Int) -> JSON? {
        get {
            if let array = data as? [AnyObject] where array.count > index {
                return JSON(array[index])
            } else {
                return nil
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09011482775836245, 'fraction_numerical': 0.006240639041437843, 'mean_word_length': 1.1111696522655428, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1050578', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1016, 'n_words': 283}