Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/netologist/yaml-object-parser
Customisable Yaml Object Parser
https://github.com/netologist/yaml-object-parser
golang golang-library json parser yaml
Last synced: 14 days ago
JSON representation
Customisable Yaml Object Parser
- Host: GitHub
- URL: https://github.com/netologist/yaml-object-parser
- Owner: netologist
- Created: 2022-05-05T15:28:07.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-07T17:50:42.000Z (over 2 years ago)
- Last Synced: 2024-10-14T22:42:18.548Z (about 1 month ago)
- Topics: golang, golang-library, json, parser, yaml
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yaml Object Parser
### Object Format
```go
type Object struct {
Name string
Level int
Children []*Object
Arguments string
}
```### Example Struct
```go
// set max depth limit
yop.SetMaxDepthLimit(2)type RuleSection struct {
Rule *yop.Object `json:"rule"`
}func (t *RuleSection) UnmarshalJSON(b []byte) (err error) {
var result map[string]json.RawMessage
if err := json.Unmarshal(b, &result); err != nil {
return err
}for key, value := range result {
if key == "rule" {
if t.Rule, err = yop.ParseObjectFromJSON(value); err != nil {
return err
}
}
}
return nil
}
```### Example Yaml File
```yaml
error-null-object:
rule: ~error-empty-object:
rule: ""error-not-found:
rule: invaliderror-tree-level-limit-exceeded:
rule:
and:
- or:
- and:
- or:
- and:
- or:
- and:
- or:
- and:
- self
- location:
abc: 123error-object-list-not-acceptable:
rule:
- self
- location:
region: ukstring-object:
rule: testobject-object:
rule:
location:
region: uklist-object:
rule:
and:
- self
- location:
region: usnested-object:
rule:
or:
- self
- and:
- location
- timenested-object-with-object:
rule:
or:
- self
- and:
- location
- opening-hours:
opening: 10:00
closing: 20:00
- relationship:
levels:
- comprehensive
- parent```