IT:AD:JSON:HowTo:Flatten JSON

Summary

You generally only need to flatten JSON when developing POCs – the rest of the time, JSON is coming out of a service, already stripped of unnecessary spacing and indenting.

There are several sites online that can do the trick:

The above tool takes:

{
    "title": "My Form",
    "sections": [
        {
            "type": "none|labelled|tab",
            "name": "grp1",
            "fields": [
                {
                    "key": "FirstName",
                    "field_type": "text",
                    "label": "First Name:",
                    "binding": "firstName",
                    "validations": [
                        {
                            "type": "required"
                        },
                        {
                            "type": "minLength",
                            "min": "1"
                        }
                    ]
                },
                {
                    "key": "Gender",
                    "field_type": "options",
                    "label": "Gender:",
                    "binding": "gender",
                    "options": "genderOptions",
                    "validations": [
                        {
                            "type": "required"
                        }
                    ]
                }
            ]
        }
    ]
}

and produces:

{"title":"My Form","sections":[{"type":"none|labelled|tab","name":"grp1","fields":[{"key":"FirstName","field_type":"text","label":"First Name:","binding":"firstName","validations":[{"type":"required"},{"type":"minLength","min":"1"}]},{"key":"Gender","field_type":"options","label":"Gender:","binding":"gender","options":"genderOptions","validations":[{"type":"required"}]}]}]}

  • /home/skysigal/public_html/data/pages/it/ad/json/howto/flatten_json.txt
  • Last modified: 2023/11/04 01:47
  • by 127.0.0.1