<commit_before>'use strict';

//
// Implements input/output for the JSON format.
//

var dataForge = require('../index');

var E = require('linq');
var assert = require('chai').assert;

module.exports = function (options) {

	if (!options) {
		options = {};
	}

	return {

		//
		// Load a DataFrame from JSON text data.
		//
		from: function (inputJsonData) {

			assert.isString(inputJsonData, "Expected 'inputJsonData' parameter to 'json.from' to be a string containing JSON data.");	

			var jsonData = JSON.parse(inputJsonData);

			var headers = E.from(jsonData)
				.selectMany(function (obj) {
					return Object.keys(obj);
				})
				.distinct()
				.toArray();

			var rows = E.from(jsonData)
				.select(function (obj) {
					return E.from(headers)
						.select(function (header) {
							return obj[header];
						})
						.toArray();
				})
				.toArray();

			return new dataForge.DataFrame({
					columnNames: headers, 
					rows: rows
				});
		},
		
		//
		// Write DataFrame to JSON text data.
		//
		to: function (dataFrame) {

			assert.isObject(dataFrame, "Expected 'dataFrame' parameter to 'json.to' to be a data frame object.");

			var columnNames = dataFrame.getColumnNames();

			return JSON.stringify(E.from(dataFrame.getValues())
				.select(function (row) {
					return E.from(columnNames)
						.select(function (columnName, columnIndex) {
							return [columnName, columnIndex];
						})
						.toObject(
							function (column) {
								var columnName = column[0];
								return columnName;
							},
							function (column) {
								var columnIndex = column[1];
								return row[columnIndex];
							}
						);
				})
				.toArray(), null, 4);
		},	
	};
};<commit_msg>Simplified json format now that data frame has toObjects function.<commit_after>'use strict';

//
// Implements input/output for the JSON format.
//

var dataForge = require('../index');

var E = require('linq');
var assert = require('chai').assert;

module.exports = function (options) {

	if (!options) {
		options = {};
	}

	return {

		//
		// Load a DataFrame from JSON text data.
		//
		from: function (inputJsonData) {

			assert.isString(inputJsonData, "Expected 'inputJsonData' parameter to 'json.from' to be a string containing JSON data.");	

			var jsonData = JSON.parse(inputJsonData);

			var headers = E.from(jsonData)
				.selectMany(function (obj) {
					return Object.keys(obj);
				})
				.distinct()
				.toArray();

			var rows = E.from(jsonData)
				.select(function (obj) {
					return E.from(headers)
						.select(function (header) {
							return obj[header];
						})
						.toArray();
				})
				.toArray();

			return new dataForge.DataFrame({
					columnNames: headers, 
					rows: rows
				});
		},
		
		//
		// Write DataFrame to JSON text data.
		//
		to: function (dataFrame) {

			assert.isObject(dataFrame, "Expected 'dataFrame' parameter to 'json.to' to be a data frame object.");

			return JSON.stringify(dataFrame.toObjects(), null, 4);
		},	
	};
};
{'fraction_non_alphanumeric': 0.14238079359786596, 'fraction_numerical': 0.001333777925975325, 'mean_word_length': 2.6101083032490973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4175296', 'n_tokens_mistral': 1231, 'n_tokens_neox': 936, 'n_words': 246}