<commit_before># -*- coding: utf-8 -*-

""" Tablib - JSON Support
"""

try:
	import json
except ImportError:
	import simplejson as json

import tablib.core


title = 'json'
extentions = ('json', 'jsn')


def export_set(dataset):
	"""Returns JSON representation of Dataset."""
	return json.dumps(dataset.dict)


def export_book(databook):
	"""Returns JSON representation of Databook."""
	return json.dumps(databook._package())
	

def import_set(dset, in_stream):
	"""Returns dataset from JSON stream."""
	
	dset.wipe()
	dset.dict = json.loads(in_stream)


def import_book(dbook, in_stream):
	"""Returns databook from JSON stream."""

	dbook.wipe()
	for sheet in json.loads(in_stream):
		data = tablib.core.Dataset()
		data.title = sheet['title']
		data.dict = sheet['data']
		dbook.add_sheet(data)


def detect(stream):
	"""Returns True if given stream is valid JSON."""
	try:
		json.loads(stream)
		return True
	except ValueError:
		return False<commit_msg>Added vendorized JSON.<commit_after># -*- coding: utf-8 -*-

""" Tablib - JSON Support
"""

try:
	import json  # load system JSON (Python >= 2.6)
except ImportError:
	try:
		import simplejson as json
	except ImportError:
		import tablib.packages.simplejson as json # use the vendorized copy

import tablib.core


title = 'json'
extentions = ('json', 'jsn')


def export_set(dataset):
	"""Returns JSON representation of Dataset."""
	return json.dumps(dataset.dict)


def export_book(databook):
	"""Returns JSON representation of Databook."""
	return json.dumps(databook._package())
	

def import_set(dset, in_stream):
	"""Returns dataset from JSON stream."""
	
	dset.wipe()
	dset.dict = json.loads(in_stream)


def import_book(dbook, in_stream):
	"""Returns databook from JSON stream."""

	dbook.wipe()
	for sheet in json.loads(in_stream):
		data = tablib.core.Dataset()
		data.title = sheet['title']
		data.dict = sheet['data']
		dbook.add_sheet(data)


def detect(stream):
	"""Returns True if given stream is valid JSON."""
	try:
		json.loads(stream)
		return True
	except ValueError:
		return False
{'fraction_non_alphanumeric': 0.13709285367039378, 'fraction_numerical': 0.0019445794846864365, 'mean_word_length': 4.41578947368421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5489663', 'n_tokens_mistral': 716, 'n_tokens_neox': 690, 'n_words': 195}