pipr.tools
Pipes
Clean Email Strip formatting from pasted email for clean plain text Clean AI Output Clean plain text from ChatGPT or AI output Decode & Format JWT Decode a JWT and pretty-print header and payload Word Frequency Count word frequency in text

json-flatten Flatten nested JSON to dot-notation paths

⟐ Data
Input0 chars
Output0 chars

Flags

--separator string default: =

Examples

Flatten nested JSON to dot-notation

Usage
"{"user":{"name":"Alice","address":{"city":"Paris"}},"tags":[..." | json-flatten

Flatten a nested config file to see all settings at a glance

Usage
"{"server":{"host":"prod.example.com","port":443,"ssl":{"enab..." | json-flatten

Flatten a nested API response for pasting into a spreadsheet

Usage
"{"order":{"id":"12345","customer":{"name":"Bob","email":"bob..." | json-flatten
View source
(input, opts = {})=>{
                try {
                    const sep = opts.separator ?? " = ";
                    const result = [];
                    const flatten = (obj, prefix)=>{
                        for (const [k, v] of Object.entries(obj)){
                            const path = prefix ? `${prefix}.${k}` : k;
                            if (v && typeof v === "object") flatten(v, path);
                            else result.push(`${path}${sep}${v}`);
                        }
                    };
                    flatten(JSON.parse(input), "");
                    return result.join("\n");
                } catch (e) {
                    return `Error: ${e.message}`;
                }
            }

Also useful for