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.
- 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
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;"
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}