Skip to content

a converter of schema of map[string]any and []any in Go

License

Notifications You must be signed in to change notification settings

Asterism12/many

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

many

A converter of schema of map[string]any and []any in Go

Usage

src:

[
  [
    {
      "a": "a1",
      "b": "b1"
    },
    {
      "a": "a2",
      "b": "b2"
    }
  ],
  [
    {
      "a": "a3",
      "b": "b3"
    },
    {
      "a": "a4",
      "b": {
        "c": "c1",
        "d": "d1"
      }
    }
  ]
]

phases:

[
  {
    "#mode": "router",
    "#array.result": "#strict.#array.#array.a"
  }
]

code:

	setter := many.New()
	var expression []map[string]any
	var src any
	_ = json.Unmarshal(expressionJSON, &expression)
	_ = json.Unmarshal(srcBys, &src)

	dst, info := setter.Set(src, nil, expression)
	bys, err := json.Marshal(dst)
	fmt.Println(string(bys), err, info)

output:

[{"result":["a1","a2"]},{"result":["a3","a4"]}] <nil> map[]

About

a converter of schema of map[string]any and []any in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages