@beohoang98/flatify-json

const {flatify} = require('@beohoang98/flatify-json'); // or in ES6 import flatify from '@beohoang98/flatify-json';

Usage no npm install needed!

<script type="module">
  import beohoang98FlatifyJson from 'https://cdn.skypack.dev/@beohoang98/flatify-json';
</script>

README

Using

const {flatify} = require('@beohoang98/flatify-json');
// or in ES6
import flatify from '@beohoang98/flatify-json';

flatify({
    something: 'here',
    root: {
        leap: "any",
        otherLeap: null,
    },
    array: [
        {
            nested: 'array',
        },
        {
            nested_object: {
                a: 1,
                b: 2,
            }
        }
    ],
});

Output:

{
    "something": "here",
    "root.leap": "any",
    "root.otherLeap": null,
    "array": [
        {"nested": "array"},
        {"nested_object.a": 1},
        {"nested_object.b": 2},
    ]
}