<commit_before>//  Created by <NAME> on 15/6/6.
//  Copyright (c) 2015年 DingSoung. All rights reserved.

import Foundation

extension NSData {
    
    /// JSON data -> JSON Object (Array or Dictionary)
    public var jsonObj: Any? {
        do {
            return try  JSONSerialization.jsonObject(with: self as Data, options: JSONSerialization.ReadingOptions.mutableLeaves)
        } catch let error as NSError {
            print("data formar fail:\(error.domain)")
            return nil
        }
    }
    
    /// JSON data -> JSON Array
    public var jsonArray: NSArray? {
        return self.jsonObj as? NSArray
    }
    
    /// JSON data -> JSON Dictionary
    public var jsonDictionary: NSDictionary? {
        return self.jsonObj as? NSDictionary
    }
    
    /// JSON Data -> JSON String
    public var jsonStr: NSString? {
        guard let str = NSString(data: self as Data, encoding: String.Encoding.utf8.rawValue) else {
            print("format \(String(describing: self)) to String fail)")
            return nil
        }
        return str
    }
    
}
<commit_msg>dict -> data -> string<commit_after>//  Created by <NAME> on 15/6/6.
//  Copyright (c) 2015年 DingSoung. All rights reserved.

import Foundation

extension NSData {
    
    /// JSON data -> JSON Object (Array or Dictionary)
    public var jsonObject: Any? {
        do {
            return try  JSONSerialization.jsonObject(with: self as Data, options: JSONSerialization.ReadingOptions.mutableLeaves)
        } catch let error as NSError {
            print("data formar fail:\(error.domain)")
            return nil
        }
    }
    
    /// JSON data -> JSON Array
    public var jsonArray: NSArray? {
        return self.jsonObject as? NSArray
    }
    
    /// JSON data -> JSON Dictionary
    public var jsonDictionary: NSDictionary? {
        return self.jsonObject as? NSDictionary
    }
    
    /// JSON Data -> JSON String
    public var jsonString: NSString? {
        guard let str = NSString(data: self as Data, encoding: String.Encoding.utf8.rawValue) else {
            print("format \(String(describing: self)) to String fail)")
            return nil
        }
        return str
    }
    
}

{'fraction_non_alphanumeric': 0.09515178975985501, 'fraction_numerical': 0.008155867693701857, 'mean_word_length': 2.0122783083219646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '2481826', 'n_tokens_mistral': 631, 'n_tokens_neox': 612, 'n_words': 200}