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.
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
}To handle JSON arrays like ["val1", "val2"]:
raw_arr := '["val1", "val2"]'
list := calljson.get_array(raw_arr)
println(list[0]) // Output: val1src(path string) Reads a file from the disk and returns it as a raw string.
get_val(key, object, raw) Extracts a string value from a specific object key.
get_array(raw) Converts a JSON array string into a V []string array.
File Safety: If src() cannot find a file, it returns a JSON string containing an error message.
Types: Currently optimized for map[string]string structures.