An open API service indexing awesome lists of open source software.

https://github.com/openpeeps/nyml

A stupid simple YAML Parser. From YAML to stringified JSON, JsonNode or Nim objects. Written in Nim language 👑
https://github.com/openpeeps/nyml

json nim nim-language nyml yaml yaml-parser yaml2json yml-parser

Last synced: 5 months ago
JSON representation

A stupid simple YAML Parser. From YAML to stringified JSON, JsonNode or Nim objects. Written in Nim language 👑

Awesome Lists containing this project

README

        


😋 A stupid simple YAML Parser.
From YAML to stringified JSON, JsonNode or Nim objects via pkg/jsony


nimble install nyml


API reference


Github Actions Github Actions

## 😍 Key Features
- [x] `integer`, `string`, `boolean`, `array`, `object`
- [x] `GET` access using `dot` annotations
- [x] Direct to object parser using [JSONY](https://github.com/treeform/jsony)
- [x] Rules and Validator
- [x] Open Source | `MIT` License

## Example

A simple YAML file

```yaml
name: test
on:
push:
paths-ignore:
- LICENSE
- README.*
pull_request:
paths-ignore:
- LICENSE
- README.*
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
nim-version:
- 'stable'
steps:
- uses: actions/checkout@v2
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: ${{ matrix.nim-version }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: nimble install -Y
- run: nim --threads:on c -r src/tim.nim
- run: nimble test

```

### Get JSON document
```nim
let contents = readFile("sample.yaml")
let jsonContents: JsonNode = yaml(contents).toJson.get
```

### Get a specific value using `.` notation
```nim
let osName: JsonNode = yaml(contents).toJson.get("jobs.test.runs-on")
echo osName.getStr
```

### Handle variables

```nim
let example = """
name: ${{username}}
"""
let yml = yaml(example, data = %*{"username": "John Do The Do"})
echo yml # {"name": "John Do The Do"}
```

### Dump YAML to stringified JSON
```nim
echo yaml(contents)

# dump to json with indentation
echo yaml(contents, true)

```

### ❤ Contributions & Support
- 🐛 Found a bug? [Create a new Issue](https://github.com/openpeeps/nyml/issues)
- 👋 Wanna help? [Fork it!](https://github.com/openpeeps/nyml/fork)
- 😎 [Get €20 in cloud credits from Hetzner](https://hetzner.cloud/?ref=Hm0mYGM9NxZ4)
- 🥰 [Donate to OpenPeeps via PayPal address](https://www.paypal.com/donate/?hosted_button_id=RJK3ZTDWPL55C)

### 🎩 License
`MIT` license. [Made by Humans from OpenPeeps](https://github.com/openpeeps).

Copyright © 2023 OpenPeeps & Contributors — All rights reserved.