npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

object-flatify

v2.1.0

Published

Transforms complex nested objects and arrays into a single-level structure, including array indices in the column names. This conversion simplifies the representation of hierarchical data, making it easier to work with in tabular formats. By flattening th

Readme

Object-Flatify

Transforms nested objects and arrays into a single-level structure with dot notation keys, including array indices. This simplifies hierarchical data for tabular formats like CSV or Excel, aiding data manipulation, analysis, and export for reporting or visualization.

Table of Contents

Installation

npm install object-flatify

Usage

TypeScript:

import * as objectFlatify from "object-flatify";
import { ObjectFlattener } from "object-flatify";

JavaScript:

const objectFlatify = require("object-flatify");
const { ObjectFlattener } = require("object-flatify");

ObjectFlattener.toDotNotation(input)

Flattens a nested object into a single-level object with dot notation keys.

Parameters

  • input: Object
    • A valid JavaScript object (e.g., { a: { b: { c: 1 } } }).

Returns

  • Object
    • A single-level object (e.g., { 'a.b.c': 1 }).

ObjectFlattener.toDataTableFromObject(input, [options])

Flattens a nested object into an array of single-level objects for tabular data.

Parameters

  • input: Object
    • A valid JavaScript object.
  • options: Object (Optional)
    • batchSize: number - Processes data in chunks for memory optimization.
    • keysAsColumn: boolean - Generates columns from object keys.

Returns

  • Array of Object
    • Array of single-level objects with dot notation keys.

ObjectFlattener.toDataTableFromListAsStream(input, [options])

Flattens a list of nested objects into a stream of single-level objects.

Parameters

  • input: Object[]
    • Array of valid JavaScript objects.
  • options: Object (Optional)
    • batchSize: number - Processes data in chunks.
    • keysAsColumn: boolean - Generates columns from object keys.

Returns

  • Readable Stream
    • Emits events with:
      • data: Array of single-level objects.
      • dataSetLength: Total dataset length.
      • dataProcessed: Count of processed items.
      • completed: Boolean indicating completion.

ObjectFlattener.toDataTableFromFile(input, [options])

Flattens a JSON file (local or remote URL) into a stream of single-level objects.

Parameters

  • input: string
    • Path or URL to a JSON file (e.g., ./file.json or https://example.com/file.json).
  • options: Object (Optional)
    • batchSize: number - Processes data in chunks.
    • keysAsColumn: boolean - Generates columns from object keys.

Returns

  • Readable Stream
    • Same event structure as toDataTableFromListAsStream.

Examples

Dot Notation Conversion

const { ObjectFlattener } = require("object-flatify");
const DOCUMENT = {
  company: {
    name: "Tech Innovators Inc.",
    departments: [
      {
        name: "R&D",
        teams: [
          {
            name: "AI Team",
            projects: [
              {
                projectId: "P001",
                tasks: [{ taskId: "T1001", description: "Develop module" }],
              },
            ],
          },
        ],
      },
    ],
  },
};

const flattened = ObjectFlattener.toDotNotation(DOCUMENT);
console.log(flattened);
/*
{
  'company.name': 'Tech Innovators Inc.',
  'company.departments[0].name': 'R&D',
  'company.departments[0].teams[0].name': 'AI Team',
  'company.departments[0].teams[0].projects[0].projectId': 'P001',
  'company.departments[0].teams[0].projects[0].tasks[0].taskId': 'T1001',
  'company.departments[0].teams[0].projects[0].tasks[0].description': 'Develop module'
}
*/

Data Table Conversion

const flattened = ObjectFlattener.toDataTableFromObject(DOCUMENT, {
  keysAsColumn: true,
});
console.log(flattened);
/*
{
  keysAsColumn: Set(['company.name', 'company.departments.name', ...]),
  data: [{
    'company.name': 'Tech Innovators Inc.',
    'company.departments.name': 'R&D',
    'company.departments.teams.name': 'AI Team',
    'company.departments.teams.projects.projectId': 'P001',
    'company.departments.teams.projects.tasks.taskId': 'T1001',
    'company.departments.teams.projects.tasks.description': 'Develop module'
  }],
  dataProcessed: 1,
  dataSetLength: 1,
  completed: true,
  isError: false
}
*/

Stream-Based Processing (List)

const { Readable } = require("stream");
const flattened$ = ObjectFlattener.toDataTableFromListAsStream(
  [DOCUMENT, DOCUMENT],
  { keysAsColumn: true, batchSize: 1 }
);
flattened$.on("data", (data) => console.log("Chunk:", data));
flattened$.on("end", (data) => console.log("Completed:", data));
/*
Chunk: {
  data: [{
    'company.name': 'Tech Innovators Inc.',
    'company.departments.name': 'R&D',
    ...
  }],
  keysAsColumn: Set([...]),
  dataProcessed: 1,
  dataSetLength: 2,
  completed: false,
  isError: false
}
Completed: {
  keysAsColumn: Set([...]),
  dataProcessed: 2,
  dataSetLength: 2,
  completed: true,
  isError: false
}
*/

File-Based Processing (Local or Remote)

const { Readable } = require("stream");
const { ObjectFlattener } = require("object-flatify");

// Local File
const localStream = ObjectFlattener.toDataTableFromFile(
  "./dist/mock/file.json",
  { keysAsColumn: true }
);
localStream.on("data", (data) => console.log("Local Chunk:", data));
localStream.on("end", (data) => console.log("Local Completed:", data));

// Remote File
const remoteStream = ObjectFlattener.toDataTableFromFile(
  "https://examples/file.json",
  { keysAsColumn: true }
);
remoteStream.on("data", (data) => console.log("Remote Chunk:", data));
remoteStream.on("end", (data) => console.log("Remote Completed:", data));

/*
Local Chunk: {
  data: [
    { 'sepal.length': 7.4, 'sepal.width': 2.8, 'petal.length': 6.1, 'petal.width': 1.9, variety: 'Virginica' },
    ...
  ],
  keysAsColumn: Set(['sepal.length', 'sepal.width', 'petal.length', 'petal.width', 'variety']),
  dataProcessed: 10,
  dataSetLength: 150,
  completed: false,
  isError: false
}
Local Completed: {
  keysAsColumn: Set(['sepal.length', 'sepal.width', 'petal.length', 'petal.width', 'variety']),
  dataProcessed: 150,
  dataSetLength: 150,
  completed: true,
  isError: false
}

Remote Chunk: {
  data: [
    { 'sepal.length': 7.4, 'sepal.width': 2.8, 'petal.length': 6.1, 'petal.width': 1.9, variety: 'Virginica' },
    ...
  ],
  keysAsColumn: Set(['sepal.length', 'sepal.width', 'petal.length', 'petal.width', 'variety']),
  dataProcessed: 10,
  dataSetLength: 150,
  completed: false,
  isError: false
}
Remote Completed: {
  keysAsColumn: Set(['sepal.length', 'sepal.width', 'petal.length', 'petal.width', 'variety']),
  dataProcessed: 150,
  dataSetLength: 150,
  completed: true,
  isError: false
}
*/

Contributing

Contribute via GitHub:

License

MIT License. See LICENSE file.

Author

Created by Amitabh Anand.