Module std::encoding::json

JSON parsing and manipulation.

Parse JSON strings into values, inspect their types, extract fields, and convert back to JSON text.

Examples

import std::encoding::json;

fn main() {
    let val = json.parse("{\"name\": \"Hew\", \"version\": 1}");
    let name = val.get_field("name");
    println(name.get_string());
    name.free();
    val.free();
}

Contents

Functions

Function parse

pub fn parse(s: String) -> Value

Parse a JSON string into a Value.

Panics if the input is not valid JSON.

Examples

let obj = json.parse("{\"key\": [1, 2, 3]}");

Types

Struct Value

An opaque JSON value.

Represents any JSON type: null, bool, integer, float, String, array, or object. Created by json.parse(s) or by navigating into a parsed value. Must be freed with free() when no longer needed.

Traits

Trait ValueMethods

Methods available on a JSON Value.

Methods

fn stringify(self: Value) -> String fn type_of(self: Value) -> i32 fn get_bool(self: Value) -> i32 fn get_int(self: Value) -> i64 fn get_float(self: Value) -> f64 fn get_string(self: Value) -> String fn get_field(self: Value, key: String) -> Value fn array_len(self: Value) -> i32 fn array_get(self: Value, index: i32) -> Value fn keys(self: Value) -> Value fn free(self: Value)