v / vlib / json
0 issues 1 contributor 4 branches 0 releases
Clone with HTTPS:

About

README
  V 99.7% 272k loc
  JavaScript 0.1% 344 loc
  C 0% 63 loc
  C++ 0% 95 loc
  Go 0% 63 loc
52 years ago
..

Description:

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
}