60 lines
782 B
Markdown
60 lines
782 B
Markdown
# Go JSON Mapper (gojsonmapper)
|
|
|
|
This is a simple library that allows you to map different JSON objects to each other.
|
|
|
|
## Example
|
|
|
|
This example shows how to map a JSON object to another JSON object.
|
|
|
|
### Mapping
|
|
|
|
```json
|
|
{
|
|
"name": "data.name",
|
|
"address": "data.addresses[0]"
|
|
}
|
|
````
|
|
|
|
### Input JSON
|
|
|
|
```json
|
|
{
|
|
"data": {
|
|
"name": "John Doe",
|
|
"addresses": [
|
|
"123 Main St"
|
|
]
|
|
}
|
|
}
|
|
```
|
|
|
|
### Output JSON
|
|
|
|
```json
|
|
{
|
|
"name": "John Doe",
|
|
"address": "123 Main St"
|
|
}
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Read Mapping
|
|
|
|
```go
|
|
mapping, err := ReadMapping("mapping.json")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
```
|
|
|
|
### Map Input
|
|
|
|
```go
|
|
mapper := NewMapper(mapping)
|
|
output, err := mapper.Map(input)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Println(output)
|
|
``` |