std/data/kdl/json

Standard Library documentation

JSON-in-KDL structure conversion.

Module

Name
std/data/kdl/json
Area
Standard Library
Source
modules/std/data/kdl/json.zzm

NAME

std/data/kdl/json - JSON-in-KDL structure conversion.

SYNOPSIS

  from std/data/kdl import KDL;
  from std/data/kdl/json import kdl_to_json, json_to_kdl;

  let kdl_doc := ( new KDL() ).decode( """- foo=1 bar=#true""" );
  let data := kdl_to_json(kdl_doc);
  let roundtrip := json_to_kdl(data);

IMPLEMENTATION SUPPORT

This module is supported by all implementations of ZuzuScript.

DESCRIPTION

This module implements the JSON-in-KDL (JiK) mapping for parsed Zuzu objects. kdl_to_json accepts a KDLDocument or KDLNode and returns native Zuzu data structures. json_to_kdl accepts native JSON-like data structures and returns a KDLDocument.

kdl_to_json(value, pairlists: true) maps object-like JiK nodes to PairList values instead of Dict values, preserving key order and duplicate keys.

EXPORTS

Functions

  • kdl_to_json(value, ... PairList opts)

    Parameters: value is a KDLDocument, KDLNode, or compatible KDL value and opts may include pairlists. Returns: value. Converts JSON-in-KDL structures into native JSON-like ZuzuScript data.

  • json_to_kdl(value)

    Parameters: value is a JSON-like ZuzuScript value. Returns: KDLDocument. Converts native JSON-like data into JSON-in-KDL nodes.

COPYRIGHT AND LICENCE

std/data/kdl/json is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.