Home

Welcome to
﹛JsonFlat.com﹜

The JsonFlat.com site is a simple API for collapsing and expanding JSON documents.

But Why Would I Want to Do That?

Because sometimes you need deeply nested JSON documents to be expressed as simple key, value pairs. For instance, saving to a database (without JSON support) or even in Redis.

In these scenarios you can use a key like "key[0].val2[0]": "My Value" that later can be expanded back to
{"key": [{"val2": ["My Value"]}]}


ℹ️ How to Use the API

Collapse API

Take a normal JSON data structure and collapse into key, value pairs.
Note, a JSON document is returned by the API.

curl -XPOST https://jsonflat.com/collapse -d '
    {
      "hello": [
        {"value": "world"},
        {"key": [{"val": 1, "val2": [1,2,3]}]}
      ]
    }
  '

Expand API

The inverse of the above. Take a collapsed JSON data structure and turn it back its original JSON document.

curl -XPOST https://jsonflat.com/expand -d '
    {
      "hello[0].value": "world",
      "hello[1].key[0].val":1,
      "hello[1].key[0].val2[0]":1,
      "hello[1].key[0].val2[1]":2,
      "hello[1].key[0].val2[2]":3
    }
  '