UNPKG

danfojs

Version:

JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.

79 lines (77 loc) 2.75 kB
/** * @license * Copyright 2022 JsData. All rights reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================================== */ import { JsonInputOptionsBrowser, JsonOutputOptionsBrowser } from '../../shared/types'; import { DataFrame, NDframe, Series } from '../../'; /** * Reads a JSON file from local or remote location into a DataFrame. * @param fileName URL or local file path to JSON file. * @param options Configuration object. Supported options: * - `method`: The HTTP method to use. Defaults to `'GET'`. * - `headers`: Additional headers to send with the request. Supports the `node-fetch` [HeadersInit] * @example * ``` * import { readJSON } from "danfojs-node" * const df = await readJSON("https://raw.githubusercontent.com/test.json") * ``` * @example * ``` * import { readJSON } from "danfojs-node" * const df = await readJSON("https://raw.githubusercontent.com/test.json", { * headers: { * Accept: "text/json", * Authorization: "Bearer YWRtaW46YWRtaW4=" * } * }) * ``` * @example * ``` * import { readJSON } from "danfojs-node" * const df = await readJSON("./data/sample.json") * ``` */ declare const $readJSON: (file: any, options?: JsonInputOptionsBrowser | undefined) => Promise<unknown>; /** * Converts a DataFrame or Series to JSON. * @param df DataFrame or Series to be converted to JSON. * @param options Configuration object. Supported options: * - `fileName`: The file path to write the JSON to. If not specified, the JSON object is returned. * - `format`: The format of the JSON. Defaults to `'column'`. E.g for using `column` format: * ``` * [{ "a": 1, "b": 2, "c": 3, "d": 4 }, * { "a": 5, "b": 6, "c": 7, "d": 8 }] * ``` * and `row` format: * ``` * { "a": [1, 5, 9], * "b": [2, 6, 10] * } * ``` * @example * ``` * import { toJSON } from "danfojs-node" * const df = new DataFrame([[1, 2, 3], [4, 5, 6]]) * const json = toJSON(df) * ``` * @example * ``` * import { toJSON } from "danfojs-node" * const df = new DataFrame([[1, 2, 3], [4, 5, 6]]) * toJSON(df, { * fileName: "./data/sample.json", * format: "row" * }) * ``` */ declare const $toJSON: (df: NDframe | DataFrame | Series, options?: JsonOutputOptionsBrowser | undefined) => object | void; export { $readJSON, $toJSON };