<commit_before>//
//  JSON.swift
//  JSONParsing
//
//  Created by <NAME> on 06/10/15.
//  Copyright © 2015 Fueled. All rights reserved.
//

import Foundation

public final class JSON {

	public enum Error: Swift.Error {
		case noValue(json: JSON)
		case typeMismatch(json: JSON)
	}

	public let parentLink: (JSON, String)?
	public let object: AnyObject?

	public init(_ object: AnyObject?) {
		self.object = object
		self.parentLink = nil
	}

	public init(_ object: AnyObject?, parent: JSON, key: String) {
		self.object = object
		self.parentLink = (parent, key)
	}

	public var pathFromRoot: String {
		if let (parent, key) = self.parentLink {
			return "\(parent.pathFromRoot)/\(key)"
		} else {
			return ""
		}
	}

	public subscript(key: String) -> JSON {
		let value = (object as? NSDictionary)?[key]
		return JSON(value as AnyObject?, parent: self, key: key)
	}

	public var array: [JSON] {
		if let arr = object as? [AnyObject] {
			return arr.enumerated().map {
				idx, item in
				JSON(item, parent: self, key: "\(idx)")
			}
		} else {
			return [self]
		}
	}

	public var optional: JSON? {
		if object == nil || object is NSNull {
			return nil
		} else {<commit_msg>Use Any instead of AnyObject<commit_after>//
//  JSON.swift
//  JSONParsing
//
//  Created by <NAME> on 06/10/15.
//  Copyright © 2015 Fueled. All rights reserved.
//

import Foundation

public final class JSON {

	public enum Error: Swift.Error {
		case noValue(json: JSON)
		case typeMismatch(json: JSON)
	}

	public let parentLink: (JSON, String)?
	public let object: Any?

	public init(_ object: Any?) {
		self.object = object
		self.parentLink = nil
	}

	public init(_ object: Any?, parent: JSON, key: String) {
		self.object = object
		self.parentLink = (parent, key)
	}

	public var pathFromRoot: String {
		if let (parent, key) = self.parentLink {
			return "\(parent.pathFromRoot)/\(key)"
		} else {
			return ""
		}
	}

	public subscript(key: String) -> JSON {
		let value = (object as? NSDictionary)?[key]
		return JSON(value as Any?, parent: self, key: key)
	}

	public var array: [JSON] {
		if let arr = object as? [Any] {
			return arr.enumerated().map {
				idx, item in
				JSON(item, parent: self, key: "\(idx)")
			}
		} else {
			return [self]
		}
	}

	public var optional: JSON? {
		if object == nil || object is NSNull {
			return nil
		} else {
{'fraction_non_alphanumeric': 0.13549211759693225, 'fraction_numerical': 0.008521516829995739, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2060357', 'n_tokens_mistral': 913, 'n_tokens_neox': 804, 'n_words': 258}