github.com/kaptinlin/jsonschema@v0.4.6/examples/unmarshaling/README.md (about)

     1  # Unmarshaling Example
     2  
     3  Shows how to unmarshal data with validation and default value application.
     4  
     5  ## What it shows
     6  
     7  - `Unmarshal()` method validates and unmarshals data
     8  - Default values from schema are automatically applied
     9  - Validation errors during unmarshal
    10  - Unmarshal to structs or maps
    11  
    12  ## Key Features
    13  
    14  - Validates data before unmarshaling
    15  - Applies schema defaults to missing fields
    16  - Returns validation errors if data is invalid
    17  - Works with JSON, maps, and structs as input
    18  
    19  ## Run
    20  
    21  ```bash
    22  go run main.go
    23  ```
    24  
    25  ## Output
    26  
    27  ```
    28  Unmarshaling with Defaults
    29  ==========================
    30  1. JSON with missing optional fields:
    31     Result: {Name:Alice Age:25 Country:US Active:true}
    32  
    33  2. Map with some values provided:
    34     Result: {Name:Bob Age:30 Country:Canada Active:true}
    35  
    36  3. Validation failure during unmarshal:
    37     Error: validation failed: name: [Value should be at least 1 characters long], age: [Value should be at least 0]
    38  
    39  4. Unmarshal to map:
    40     Result: map[active:true age:35 country:US name:Charlie]
    41  ```