Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
json.c File Reference

JSON extension helpers and VM opcode cases (conditional build). More...

#include "value.h"
#include "vm.h"
#include <json-c/json.h>
#include <string.h>
Include dependency graph for json.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static Value json_to_fun (json_object *j)
 Convert a json-c object into a Fun Value.
static json_object * fun_to_json (const Value *v)
 Convert a Fun Value into a json-c object.

Detailed Description

JSON extension helpers and VM opcode cases (conditional build).

Provides conversions between json-c objects and the Fun Value type and supplies VM opcode case implementations when FUN_WITH_JSON is enabled. This unit may be included or compiled conditionally based on build flags.

Definition in file json.c.

Function Documentation

◆ fun_to_json()

json_object * fun_to_json ( const Value * v)
static

Convert a Fun Value into a json-c object.

Produces a newly-allocated json_object tree representing the supplied Value. Unsupported Fun types are stringified using a placeholder.

Parameters
vPointer to the source Value. Must not be NULL.
Returns
Newly created json_object* on success. The caller owns the returned object and must release it with json_object_put().

Definition at line 99 of file json.c.

◆ json_to_fun()

Value json_to_fun ( json_object * j)
static

Convert a json-c object into a Fun Value.

Maps json-c primitive and compound types to the closest Fun Value representation.

  • null -> Nil
  • boolean -> Bool
  • number (int/double) -> Int/Float
  • string -> String
  • array -> Array (recursively converted)
  • object -> Map<string,any> (values recursively converted)
Parameters
jPointer to a json_object; may be NULL.
Returns
A Value representing the converted JSON data. Ownership of the returned Value belongs to the caller and must be freed with free_value() when no longer needed.

Definition at line 46 of file json.c.