Skip to content

json-flattener helps in flattening complex nested JSONs in different ways

License

Notifications You must be signed in to change notification settings

anshal21/json-flattener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT Go Report Card

json-flattener

json-flattener helps in flattening complex nested JSONs in different ways

Installation

go get github.com/anshal21/json-flattener

Examples

   jsonStr := `{
   	"isbn": "123-456-222",
   	"author": {
   	  "lastname": "Doe",
   	  "firstname": "Jane"
   	},
   	"editor": {
   	  "lastname": "Smith",
   	  "firstname": "Jane"
   	},
   	"title": "The Ultimate Database Study Guide",
   	"category": [
   	  "Non-Fiction",
   	  "Technology"
   	]
     }`

   flattnedJSON, err := flattener.FlattenJSON(jsonStr, flattener.DotSeparator)
    {
        "author.firstname": "Jane",
        "author.lastname": "Doe",
        "category.0": "Non-Fiction",
        "category.1": "Technology",
        "editor.firstname": "Jane",
        "editor.lastname": "Smith",
        "isbn": "123-456-222",
        "title": "The Ultimate Database Study Guide"
    }
   jsonStr := `{
   	"isbn": "123-456-222",
   	"author": {
   	  "lastname": "Doe",
   	  "firstname": "Jane"
   	},
   	"editor": {
   	  "lastname": "Smith",
   	  "firstname": "Jane"
   	},
   	"title": "The Ultimate Database Study Guide",
   	"category": [
   	  "Non-Fiction",
   	  "Technology"
   	]
     }`

   flattnedJSON, err := flattener.FlattenJSON(jsonStr, flattener.DotSeparator, flattener.IgnoreArray())
    {
        "author.firstname": "Jane",
        "author.lastname": "Doe",
        "category": [
            "Non-Fiction",
            "Technology"
        ],
        "editor.firstname": "Jane",
        "editor.lastname": "Smith",
        "isbn": "123-456-222",
        "title": "The Ultimate Database Study Guide"
    }
   jsonStr := `{
   	"isbn": "123-456-222",
   	"author": {
   	  "lastname": "Doe",
   	  "firstname": "Jane"
   	},
   	"editor": {
   		"v1.0.0": {
   			"lastname": "Smith",
   			"firstname": "Jane"
   		},
   		"v2.0.0": {
   			"lastname": "Doe",
   			"firstname": "John"
   		}
   	},
   	"title": "The Ultimate Database Study Guide",
   	"category": [
   	  "Non-Fiction",
   	  "Technology"
   	]
     }`

   flattnedJSON, err := flattener.FlattenJSON(jsonStr, flattener.DotSeparator, flattener.WithDepth(2))
    {
        "author.firstname": "Jane",
        "author.lastname": "Doe",
        "category.0": "Non-Fiction",
        "category.1": "Technology",
        "editor.v1.0.0": {
            "firstname": "Jane",
            "lastname": "Smith"
        },
        "editor.v2.0.0": {
            "firstname": "John",
            "lastname": "Doe"
        },
        "isbn": "123-456-222",
        "title": "The Ultimate Database Study Guide"
    }

About

json-flattener helps in flattening complex nested JSONs in different ways

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages