@retrohacker/objectify

Recursively convert an object with arrays to an object with objects

Usage no npm install needed!

<script type="module">
  import retrohackerObjectify from 'https://cdn.skypack.dev/@retrohacker/objectify';
</script>

README

objectify

A little library that recursively converts an object with arrays to an object with objects.

Install

yarn add @retrohacker/objectify

Usage

objectify({
  'foo': [
    { 'a': 1 },
    { 'b': 2 }]
  }
)

yields

{
  'foo': {
    'foo_0': { 'a': 1 },
    'foo_1': { 'b': 2 }
  }
}

and

{
  'foo': [1, 2, 3],
  'bar': ['a', 'b', 'c']
}

yields

{
  'foo': [1, 2, 3],
  'bar': ['a', 'b', 'c']
}