YANG JSON / RFC 7951 · RFC 7952

Read YANG JSON as typed Ruby values

Read, validate, and write RFC 7951 YANG JSON with RFC 7952 metadata. Supply a schema as a Ruby hash or JSON document, without an external schema compiler or subprocess.

Quick startRuby
require "yang_json"

schema = YangJSON::Schema.new({
  "modules" => { "orchard" => ["o", "urn:example:orchard"] },
  "tree" => { "orchard:grove" => ["container", { "count" => ["leaf", "uint64"] }] },
  "annotations" => {}
})
data = YangJSON.decode('{"orchard:grove":{"count":"123"}}', schema)
data["orchard:grove"]["orchard:count"] # => 123
YangJSON.encode(data, schema)           # => '{"orchard:grove":{"count":"123"}}'
schema.lookup("/orchard:grove/count").type # => "uint64"
YangJSON.validate('{"orchard:grove":{"count":123}}', schema).first.pointer
# => "/orchard:grove/count"

Installation

Add the gem to your Gemfile:

gem "yang_json"

Run bundle install, then try the quick start. Requires Ruby 3.3 or later.

For supported dependencies and optional integrations, see the installation guide.

Scope & documentation

Schemas must provide resolved node types. Parsing or compiling YANG/YIN, full semantic or datastore validation, and NETCONF/RESTCONF transport are outside scope. The schema format does not express constraints such as must/when or leafref target existence.

Read the full documentation for supported formats, examples, and API details.