Skip to content

Json API implementation for SourceMod

License

GPL-3.0, GPL-3.0 licenses found

Licenses found

GPL-3.0
LICENSE
GPL-3.0
COPYING
Notifications You must be signed in to change notification settings

rejchev/sm-jansson

Repository files navigation

Jansson

CI Discord Downloads LICENSE

About

This is an extension that implements Json API for SourceMod based on Jansson

Required dependencies

Supported OS

  • Windows
  • Linux

Supported SDK

  • Any

Getting Started

Installation

  1. Go on releases
  2. Download release for your OS
  3. Unpack on your dedicated game server
  4. Congratulation 🥳

Usage

SourcePawn API

// if u need to use simple json builder
#define JSON_INCLUDE_BUILDER

// lib
#include <jansson>

// some func
public void OnMapStart() {
    
    // empty JsonObject
    Json jsonObject = new Json("{}");
    
    // empty JsonArray
    Json jsonArray = new Json("[]");
    
    // { 
    //      "array": [
    //          
    //      ] 
    // }
    asJSONO(jsonObject).Set("array", jsonArray);
    
    delete jsonArray;
    
    // simple builder
    jsonObject = asJSONB(jsonObject)
        .SetInt("int", 12)
        .SetString("string", "rejchev")
        .SetFloat("float", 111.111)
        .SetInt64("int64", "9999999999999")
        .Build();
    
    // ...
    
    char buffer[1024];
    if(!jsonObject.Dump(buffer, sizeof(buffer), JsonPretty(4)|JsonRealPrecision(3), true))
        delete jsonObject;
    
    LogMessage(buffer);
    
    // output:
    //
    // { 
    //      "array": [
    //          
    //      ],
    //      "int":  12,
    //      "string":   "rejchev",
    //      "float":    111.111,
    //      "int64":    9999999999999
    // }
}

Another example: test.sp
More information: jansson.inc

SourceMod Extension API

#include <IJansson.h>

nJansson::IJansson* g_pJansson = nullptr;

void Sample::SDK_OnAllLoaded()
{
	SM_GET_LATE_IFACE(JANSSON, g_pJansson);
}

Header: IJansson.h
More information: SourceMod WiKi

License

Distributed under the GPL-3.0 License. See LICENSE.txt for more information.

How to contact me