https://github.com/hopsoft/kvn
KVN (Key/Value Notation) converter & parser
https://github.com/hopsoft/kvn
data-structures deserialization key-value ruby serialization
Last synced: 6 months ago
JSON representation
KVN (Key/Value Notation) converter & parser
- Host: GitHub
- URL: https://github.com/hopsoft/kvn
- Owner: hopsoft
- License: mit
- Created: 2016-03-29T03:13:27.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-20T21:50:02.000Z (about 5 years ago)
- Last Synced: 2025-04-10T02:17:02.197Z (6 months ago)
- Topics: data-structures, deserialization, key-value, ruby, serialization
- Language: Ruby
- Homepage:
- Size: 19.5 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
[](https://codeclimate.com/github/hopsoft/kvn/maintainability)
[](https://travis-ci.org/hopsoft/kvn)
[](https://coveralls.io/r/hopsoft/kvn?branch=master)
[](http://rubygems.org/gems/kvn)# KVN (kĕ'vĭn)
## Key/Value Notation
```
name:kvn; pronunciation:kĕ'vĭn; summary:Key/Value Notation;
```Similar to JSON but narrower in scope.
Represents basic key/value data structures as legible strings.
Useful when working with limited storage options to capture complex data in a single field.## Rules
* Key & value are delimited with a colon `:`
* Key/value pairs are delimited with a semicolon `;`
* Colons & semicolons are reserved & are prohibited in keys & values
* Data structures should be flat— 1 level deep, no nesting
* Keys & values are limited to primitive types
* Boolean
* String
* Numeric
* Keys are sorted alphabetically## Examples
### Convert a Hash to a KVN string
```ruby
data = { d: "example with whitespace", a: true, c: "example", b: 1, e: nil }
Kvn::Converter.new(data).convert
# => "a:true; b:1; c:example; d:example with whitespace; e:null;"
```### Parse a KVN string into a Hash
```ruby
value = "a:true; b:1; c:example; d:example with whitespace; e:null;"
Kvn::Parser.new(value).parse
# => {"a"=>true, "b"=>1, "c"=>"example", "d"=>"example with whitespace", "e"=>nil}
```