Repository

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) 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.

Notes

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.

About

Call json easily in V. Please just read the readme.md in the repo.

0
0
3 days ago

Author

horizon-std