Skip to content

hopsoft/kvn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lines of Code Maintainability Build Status Coverage Status Downloads

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

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

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}