Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rejchev/sm-jansson

Json API implementation for SourceMod
https://github.com/rejchev/sm-jansson

any csgo css extension jansson json json-api l4d l4d2 sourcemod tf2

Last synced: about 1 month ago
JSON representation

Json API implementation for SourceMod

Awesome Lists containing this project

README

        

Jansson


[![CI](https://github.com/rejchev/sm-jansson/actions/workflows/ci.yml/badge.svg)](https://github.com/rejchev/sm-jansson/)
[![Discord](https://img.shields.io/discord/1159851636156530800?logo=discord&logoColor=%23959da5&color=%235865F2
)](https://discord.gg/BAUwTKVJut)
[![Downloads](https://img.shields.io/github/downloads/rejchev/sm-jansson/total?color=%2332c955)]()
[![LICENSE](https://img.shields.io/github/license/rejchev/sm-jansson)](LICENSE)

## About
This is an extension that implements Json API for SourceMod based on [Jansson](https://github.com/akheron/jansson)

### Required dependencies

- [SourceMod](https://www.sourcemod.net/downloads.php?branch=stable)

### Supported OS
- Windows
- Linux

### Supported SDK
- Any

## Getting Started

### Installation

1. Go on [releases](https://github.com/rejchev/sm-jansson/releases)
2. Download release for your OS
3. Unpack on your dedicated game server
4. Congratulation 🥳

## Usage

### SourcePawn API

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

// lib
#include

// 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](https://github.com/rejchev/sm-jansson/blob/main/pawn/scripting/test.sp)
More information: [jansson.inc](https://github.com/rejchev/sm-jansson/blob/main/pawn/scripting/include/jansson.inc)

### SourceMod Extension API
```c++

#include

nJansson::IJansson* g_pJansson = nullptr;

void Sample::SDK_OnAllLoaded()
{
SM_GET_LATE_IFACE(JANSSON, g_pJansson);
}
```
Header: [IJansson.h](https://github.com/rejchev/sm-jansson/blob/main/public/IJansson.h)
More information: [SourceMod WiKi](https://wiki.alliedmods.net/Writing_Extensions)

## License

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

## How to contact me

- [@On DiscordServer](https://discord.gg/ChTyPUG) - `rej.chev`
- [@On GitHub](https://github.com/rejchev)