Module json stdlib

json
Version:
0.3.3
License:
MIT
Dependencies from vmod:
0
Imports:
0
Imported by:
2
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.

Imports

This section is empty.

Imported by

Overview

json provides encoding/decoding of V data structures to/from JSON.

Examples:

import json

enum JobTitle {
    manager
    executive
    worker
}

struct Employee {
    name   string
    age    int
    salary f32
    title  JobTitle
}

fn main() {
    x := Employee{'Peter', 28, 95000.5, .worker}
    println(x)
    //
    s := json.encode(x)
    println('Employee x: ${s}')
    assert s == '{"name":"Peter","age":28,"salary":95000.5,"title":2}'
    //
    y := json.decode(Employee, s)!
    //
    println(y)
    assert y == x
}

Aliases

This section is empty.

Constants

#constant used

pub const used = 1

Sum types

This section is empty.

Functions

#fn decode

fn decode(typ voidptr, s string) !voidptr

decode tries to decode the provided JSON string, into a V structure.

If it can not do that, it returns an error describing the reason for the parsing failure.

#fn encode

fn encode(x voidptr) string

encode serialises the provided V value as a JSON string, optimised for shortness.

#fn encode_pretty

fn encode_pretty(x voidptr) string

encode_pretty serialises the provided V value as a JSON string, in a formatted way, optimised for viewing by humans.

Structs

#struct C.cJSON

pub struct C.cJSON {
	valueint    int
	valuedouble f64
	valuestring &char
}

Interfaces

This section is empty.

Enums

This section is empty.