callJson for V
A simple V library to load and extract data from JSON files. This module allows you to read external files and pull specific values from JSON objects and arrays.
1. Basic Example
If you have a file at Data/data.json:
{
"Greetings": {
"hi": "hello"
}
}
You can call it in your main.v like this:
import calljson
fn main() {
// Load the raw source from a path
raw := calljson.src('../Data/data.json')
// Get the value "hello" from Greetings -> hi
w := calljson.get_val('hi', 'Greetings', raw)
println(w) // Output: hello
}
2. Working with Arrays
To handle JSON arrays like ["val1", "val2"]:
raw_arr := '["val1", "val2"]'
list := calljson.get_array(raw_arr)
println(list[0]) // Output: val1
Functions
Function Description
src(path string)
get_val(key, object, raw)
get_array(raw)
Notes
File Safety:
If src()
map[string]