PDA

View Full Version : [EXTENSION] SMJansson 2.3.1/3 (2012-05-07)


Thrawn2
05-06-2012, 19:32
This extension wraps Jansson (http://www.digip.org/jansson/), a C library for encoding, decoding and manipulating JSON data. Jansson is licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
As this is based off the 2.3.1 sources currently, I cherry picked some of the younger commits to allow building on windows.
The original sources can be found here (https://github.com/akheron/jansson).

I've adapted parts of the original documentation (http://www.digip.org/jansson/doc/2.3/) for the pawn language and recommend referring to smjansson.inc (https://raw.github.com/thraaawn/SMJansson/master/pawn/scripting/include/smjansson.inc) for SourceMod specific details. Still pretty much of it is copy'n'pasted.
Thanks to akheron (https://github.com/akheron) for providing such detailed documentation and a nice library in the first place.

The source code is hosted on github (https://github.com/thraaawn/SMJansson).
Changelog can be found here (https://github.com/thraaawn/SMJansson/commits/master).
Latest binaries here (https://github.com/thraaawn/SMJansson/tree/master/bin).

Output of the test plugin can be found here (https://gist.github.com/d8ca03d69dce065a8758).

Thrawn2
05-06-2012, 19:33
Creating basic JSON

By using reference stealing methods.
These methods automatically close the Handle of the value-object you are setting/adding/inserting, making your code much cleaner.

#pragma semicolon 1
#include <sourcemod>
#include <smjansson>

/*
*
* Example: Creating this JSON string
* {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": 1}
*
*/
public OnPluginStart() {

// Create a new JSON object
new Handle:hObj = json_object();


// Create new JSON strings/integer and 'set' them on the JSON object
// Hint: We don't need to close the handles of the values we push,
// because we are using the reference stealing method
// json_object_set_new()
json_object_set_new(hObj, "jsonrpc", json_string("2.0"));
json_object_set_new(hObj, "method", json_string("subtract"));
json_object_set_new(hObj, "id", json_integer(1));


// Create a new JSON array and add the two integers to it.
// Again, we don't need to close the hArray Handle, because we've
// pushed it to the object by reference stealing.
// This also means that the hArray handle won't be valid anymore
// afterwards.
new Handle:hArray = json_array();
json_array_append_new(hArray, json_integer(42));
json_array_append_new(hArray, json_integer(23));
json_object_set_new(hObj, "params", hArray);


// And finally transform the JSON object to a JSON string
new String:sJSON[4096];
json_dump(hObj, sJSON, sizeof(sJSON));


// And output it.
LogMessage("Created JSON is:\n%s\n", sJSON);


// Close the Handle to the JSON object, i.e. free it's memory
// and free the Handle.
CloseHandle(hObj);
}



Iterating over JSON

#pragma semicolon 1
#include <sourcemod>
#include <smjansson>

/*
*
* Example: Parsing a JSON string
*
* {
* "id": "0001",
* "type": "donut",
* "name": "Cake",
* "ppu": 0.55,
* "batters":
* {
* "batter":
* [
* { "id": "1001", "type": "Regular" },
* { "id": "1002", "type": "Chocolate" },
* { "id": "1003", "type": "Blueberry" },
* { "id": "1004", "type": "Devil's Food" }
* ]
* },
* "topping":
* [
* { "id": "5001", "type": "None" },
* { "id": "5002", "type": "Glazed" },
* { "id": "5005", "type": "Sugar" },
* { "id": "5007", "type": "Powdered Sugar" },
* { "id": "5006", "type": "Chocolate with Sprinkles" },
* { "id": "5003", "type": "Chocolate" },
* { "id": "5004", "type": "Maple" }
* ]
* }
*
*/

new String:g_sPadding[128] = " ";

public OnPluginStart() {
new String:sJSON[4096] = "{ \"id\": \"0001\", \"type\": \"donut\", \"name\": \"Cake\", \"ppu\": 0.55,";
StrCat(sJSON, sizeof(sJSON), "\"batters\": { \"batter\": [ { \"id\": \"1001\", \"type\": \"Regular\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"1002\", \"type\": \"Chocolate\" }, { \"id\": \"1003\", \"type\": \"Blueberry\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"1004\", \"type\": \"Devil's Food\" } ] },");
StrCat(sJSON, sizeof(sJSON), "\"topping\": [ { \"id\": \"5001\", \"type\": \"None\" }, { \"id\": \"5002\", \"type\": \"Glazed\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"5005\", \"type\": \"Sugar\" }, { \"id\": \"5007\", \"type\": \"Powdered Sugar\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"5006\", \"type\": \"Chocolate with Sprinkles\" }, { \"id\": \"5003\", ");
StrCat(sJSON, sizeof(sJSON), "\"type\": \"Chocolate\" }, { \"id\": \"5004\", \"type\": \"Maple\" } ]}");

// Create a new JSON object
new Handle:hObj = json_load(sJSON);

ProcessElement("root", hObj);

CloseHandle(hObj);
}


public ProcessElement(String:sKey[], Handle:hObj) {
switch(json_typeof(hObj)) {
case JSON_OBJECT: {
// It's another object
PrintToServer("%s- %s, object with %i elements", g_sPadding, sKey, json_object_size(hObj));
StrCat(g_sPadding, sizeof(g_sPadding), " ");
IterateJsonObject(Handle:hObj);
strcopy(g_sPadding, sizeof(g_sPadding), g_sPadding[2]);
}

case JSON_ARRAY: {
// It's another array
PrintToServer("%s- %s, array with %i elements", g_sPadding, sKey, json_array_size(hObj));
StrCat(g_sPadding, sizeof(g_sPadding), " ");
IterateJsonArray(Handle:hObj);
strcopy(g_sPadding, sizeof(g_sPadding), g_sPadding[2]);
}

case JSON_STRING: {
new String:sString[1024];
json_string_value(hObj, sString, sizeof(sString));
PrintToServer("%s- %-35s %s", g_sPadding, sKey, sString);
}

case JSON_INTEGER: {
PrintToServer("%s- %-35s %i", g_sPadding, sKey, json_integer_value(hObj));
}

case JSON_REAL: {
PrintToServer("%s- %-35s %f", g_sPadding, sKey, json_real_value(hObj));
}

case JSON_TRUE: {
PrintToServer("%s- %-35s %s", g_sPadding, sKey, "TRUE");
}

case JSON_FALSE: {
PrintToServer("%s- %-35s %s", g_sPadding, sKey, "FALSE");
}

case JSON_NULL: {
PrintToServer("%s- %-35s %s", g_sPadding, sKey, "NULL");
}
}

}


public IterateJsonArray(Handle:hArray) {
for(new iElement = 0; iElement < json_array_size(hArray); iElement++) {
new Handle:hValue = json_array_get(hArray, iElement);
new String:sElement[4];
IntToString(iElement, sElement, sizeof(sElement));
ProcessElement(sElement, hValue);

CloseHandle(hValue);
}
}


public IterateJsonObject(Handle:hObj) {
new Handle:hIterator = json_object_iter(hObj);

while(hIterator != INVALID_HANDLE) {
new String:sKey[128];
json_object_iter_key(hIterator, sKey, sizeof(sKey));

new Handle:hValue = json_object_iter_value(hIterator);

ProcessElement(sKey, hValue);

CloseHandle(hValue);
hIterator = json_object_iter_next(hObj, hIterator);
}
}

Thrawn2
05-11-2012, 12:28
Converting JSON to KeyValues

This is a lossy conversion as KeyValues don't support arrays as JSON does and therefore this example sets the index of the value as the key in the resulting KeyValues structure.

#pragma semicolon 1
#include <sourcemod>
#include <smjansson>

new Handle:g_hKV;

public OnPluginStart() {
// Build a JSON string without breaking the forums layout
new String:sJSON[4096] = "{ \"id\": \"0001\", \"type\": \"donut\", \"name\": \"Cake\", \"ppu\": 0.55,";
StrCat(sJSON, sizeof(sJSON), "\"batters\": { \"batter\": [ { \"id\": \"1001\", \"type\": \"Regular\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"1002\", \"type\": \"Chocolate\" }, { \"id\": \"1003\", \"type\": \"Blueberry\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"1004\", \"type\": \"Devil's Food\" } ] },");
StrCat(sJSON, sizeof(sJSON), "\"topping\": [ { \"id\": \"5001\", \"type\": \"None\" }, { \"id\": \"5002\", \"type\": \"Glazed\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"5005\", \"type\": \"Sugar\" }, { \"id\": \"5007\", \"type\": \"Powdered Sugar\" },");
StrCat(sJSON, sizeof(sJSON), "{ \"id\": \"5006\", \"type\": \"Chocolate with Sprinkles\" }, { \"id\": \"5003\", ");
StrCat(sJSON, sizeof(sJSON), "\"type\": \"Chocolate\" }, { \"id\": \"5004\", \"type\": \"Maple\" } ]}");

// Create a new JSON object
new Handle:hObj = json_load(sJSON);

g_hKV = CreateKeyValues("root");

ProcessElement("root", hObj);

KeyValuesToFile(g_hKV, "json-kv.out");
CloseHandle(g_hKV);

CloseHandle(hObj);
}


public ProcessElement(String:sKey[], Handle:hObj) {
switch(json_typeof(hObj)) {
case JSON_OBJECT: {
// It's another object
KvJumpToKey(g_hKV, sKey, true);
IterateJsonObject(Handle:hObj);
KvGoBack(g_hKV);
}

case JSON_ARRAY: {
// It's another array
KvJumpToKey(g_hKV, sKey, true);
IterateJsonArray(Handle:hObj);
KvGoBack(g_hKV);
}

case JSON_STRING: {
new String:sString[1024];
json_string_value(hObj, sString, sizeof(sString));
KvSetString(g_hKV, sKey, sString);
}

case JSON_INTEGER: {
KvSetNum(g_hKV, sKey, json_integer_value(hObj));
}

case JSON_REAL: {
KvSetFloat(g_hKV, sKey, json_real_value(hObj));
}

case JSON_TRUE: {
KvSetNum(g_hKV, sKey, 1);
}

case JSON_FALSE: {
KvSetNum(g_hKV, sKey, 0);
}

case JSON_NULL: {
KvSetString(g_hKV, sKey, "");
}
}

}


public IterateJsonArray(Handle:hArray) {
for(new iElement = 0; iElement < json_array_size(hArray); iElement++) {
new Handle:hValue = json_array_get(hArray, iElement);
new String:sElement[4];
IntToString(iElement, sElement, sizeof(sElement));
ProcessElement(sElement, hValue);

CloseHandle(hValue);
}
}


public IterateJsonObject(Handle:hObj) {
new Handle:hIterator = json_object_iter(hObj);

while(hIterator != INVALID_HANDLE) {
new String:sKey[128];
json_object_iter_key(hIterator, sKey, sizeof(sKey));

new Handle:hValue = json_object_iter_value(hIterator);

ProcessElement(sKey, hValue);

CloseHandle(hValue);
hIterator = json_object_iter_next(hObj, hIterator);
}
}


{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}

"root"
{
"root"
{
"type" "donut"
"batters"
{
"batter"
{
"0"
{
"id" "1001"
"type" "Regular"
}
"1"
{
"id" "1002"
"type" "Chocolate"
}
"2"
{
"id" "1003"
"type" "Blueberry"
}
"3"
{
"id" "1004"
"type" "Devil's Food"
}
}
}
"id" "0001"
"topping"
{
"0"
{
"id" "5001"
"type" "None"
}
"1"
{
"id" "5002"
"type" "Glazed"
}
"2"
{
"id" "5005"
"type" "Sugar"
}
"3"
{
"id" "5007"
"type" "Powdered Sugar"
}
"4"
{
"id" "5006"
"type" "Chocolate with Sprinkles"
}
"5"
{
"id" "5003"
"type" "Chocolate"
}
"6"
{
"id" "5004"
"type" "Maple"
}
}
"ppu" "0.550000"
"name" "Cake"
}
}

Converting KeyValues to JSON
#pragma semicolon 1
#include <sourcemod>
#include <smjansson>

public OnPluginStart() {
// Load some random keyvalues file
new String:sPath[PLATFORM_MAX_PATH];
Format(sPath, sizeof(sPath), "scripts/items/items_game.txt");

new Handle:hKV = CreateKeyValues("");
FileToKeyValues(hKV, sPath);

// Convert it to JSON
new Handle:hObj = KeyValuesToJSON(hKV);

// And finally save the JSON object to a file
// with indenting set to 2.
Format(sPath, sizeof(sPath), "scripts/items/items_game.json");
json_dump_file(hObj, sPath, 2);

// Close the Handle to the JSON object, i.e. free it's memory
// and free the Handle.
CloseHandle(hObj);
}



stock Handle:KeyValuesToJSON(Handle:kv) {
new Handle:hObj = json_object();

//Traverse the keyvalues structure
IterateKeyValues(kv, hObj);

//return output
return hObj;
}

IterateKeyValues(&Handle:kv, &Handle:hObj) {
do {
new String:sSection[255];
KvGetSectionName(kv, sSection, sizeof(sSection));

new String:sValue[255];
KvGetString(kv, "", sValue, sizeof(sValue));

new bool:bIsSubSection = ((KvNodesInStack(kv) == 0) || (KvGetDataType(kv, "") == KvData_None && KvNodesInStack(kv) > 0));

//new KvDataTypes:type = KvGetDataType(kv, "");
//LogMessage("Section: %s, Value: %s, Type: %d", sSection, sValue, type);

if(!bIsSubSection) {
//if(type != KvData_None) {
json_object_set_new(hObj, sSection, json_string(sValue));
} else {
//We have no value, this must be another section
new Handle:hChild = json_object();

if (KvGotoFirstSubKey(kv, false)) {
IterateKeyValues(kv, hChild);
KvGoBack(kv);
}

json_object_set_new(hObj, sSection, hChild);
}

} while (KvGotoNextKey(kv, false));
}


Using json_pack to create JSON

Pack String Rules
n Output a JSON null value. No argument is consumed.
s Output a JSON string, consuming one argument.
b Output a JSON bool value, consuming one argument.
i Output a JSON integer value, consuming one argument.
f Output a JSON real value, consuming one argument.
r Output a JSON real value, consuming one argument.
[<packstring>]

Build an array with contents from the inner format string.
Recursive value building is supported.
No argument is consumed.

{<packstring>}

Build an array with contents from the inner format string.
The first, third, etc. format character represent a key, and must be s (as object keys are always strings).
The second, fourth, etc. format character represent a value.
Recursive value building is supported.
No argument is consumed.



// Create an ADT array containing all values
// used in the json_pack string.
new Handle:hParamsArray = CreateArray(8);
PushArrayString(hParamsArray, "String");
PushArrayCell(hParamsArray, 42);
PushArrayCell(hParamsArray, 13.37);
PushArrayCell(hParamsArray, 20001.333);
PushArrayCell(hParamsArray, true);
PushArrayCell(hParamsArray, false);

// Create JSON array with
// 1. element: String
// 2. element: Integer
// 3. element: Float
// 4. element: Float
// 5. element: Boolean
// 6. element: NULL
// 7. element: Boolean
new Handle:hPackArray = json_pack("[sifrbnb]", hParamsArray);


// Create an ADT object containing all values
// used in the json_pack string.
new Handle:hParamsObject = CreateArray(16);
PushArrayString(hParamsObject, "FirstElement");
PushArrayCell(hParamsObject, 1);
PushArrayString(hParamsObject, "SecondElement");
PushArrayCell(hParamsObject, 2);

// Create JSON object with
// "FirstElement": 1
// "SecondElement": 2
// Note: You can omit the ':' and ',', they are just
// for readability.
new Handle:hPackObject = json_pack("{s:i,s:i}", hParamsObject);



// You can obviously nest and mix all of this and
// do something like this:
new Handle:hParams = CreateArray(64);
PushArrayString(hParams, "__String");
PushArrayString(hParams, "What is the \"Hitchhiker's guide to the galaxy\"?");
PushArrayString(hParams, "__Integer");
PushArrayCell(hParams, 9001);
PushArrayString(hParams, "__NestedObject");
PushArrayString(hParams, "__NestedString");
PushArrayString(hParams, "i am nested");
PushArrayString(hParams, "__Array");
PushArrayCell(hParams, 3);
PushArrayString(hParams, "4");
PushArrayString(hParams, "Extension 1");
PushArrayString(hParams, "Extension 2");
new Handle:hPacked = json_pack("{s:s,s:i,s:{s:s,s:[i,s,s,s]}}", hParams);

The last example will result in this:
{
"__String": "What is the \"Hitchhiker's guide to the galaxy\"?",
"__Integer": 9001,
"__NestedObject": {
"__NestedString": "i am nested",
"__Array": [
3,
"4",
"Extension 1",
"Extension 2"
]
}
}

berni
05-15-2012, 12:15
Good job, this can be useful for reading data object via HTTP from sourcemod plugins.

Mikeyfin
05-17-2012, 12:26
This is awesome man

Thrawn2
06-24-2012, 12:16
Updated to 2.3.1/3

Implemented json_pack() as stock.
Added remaining json types (Boolean & NULL)
Added detailed error message when a json string or file could not be loaded
Added stocks to create JSON strings according to the formatting rules (json_string_format() & json_string_format_ex()).
Added stocks to get values directly from arrays or objects, instead of having to fetch the JSON representation of it first. (json_array_get_* & json_object_get_*)
Also fixed json_string() to allow const Strings as parameter.
Added the 100th test.

alongub
06-28-2012, 17:28
If json_load returns INVALID_HANDLE, is there any way to get the error message?

Thrawn2
06-28-2012, 17:47
assuming you're using 2.3.1/3 it should be in your error log.
i'll add a native returning the errormsg in the next update.

alongub
06-28-2012, 17:50
assuming you're using 2.3.1/3 it should be in your error log.
i'll add a native returning the errormsg in the next update.

Can you also add an optional parameter for json_load that decides whether or not to report to sourcemod error log?

API
07-05-2012, 14:06
Great extension. Kind of silly there wasn't a way to parse JSON before.

francescouk
02-01-2013, 10:32
Can someone please tell how to install smjansson on css sourcemod??? I've downloaded both zip files but is giving me a error. I'm new to this whole world of css server so if someone could help me will be amazing.

bl4nk
02-01-2013, 16:18
Download the binaries package and unzip it into your extensions folder. That's the best help you're gonna get without posting the error that you're getting (post the full error message please, not just part of it).

vodka00
02-01-2013, 18:13
I am just unable to install this. Just dropped the binary files into the extensions folder and restarted the server. It won't show up in sm exts list :(

francescouk
02-01-2013, 18:49
I am just unable to install this. Just dropped the binary files into the extensions folder and restarted the server. It won't show up in sm exts list :(

You need to install the last snapshot of the sourcemod
http://sourcemod.net/snapshots.php

vodka00
02-01-2013, 18:55
You need to install the last snapshot of the sourcemod
http://sourcemod.net/snapshots.php

I did mayte and still nothing I believe.

] rcon sm exts list
[SM] Displaying 16 extensions:
[01] Automatic Updater (1.5.0-dev+3761): Updates SourceMod gamedata files
[02] Webternet (1.5.0-dev+3761): Extension for interacting with URLs
[03] CS Tools (1.5.0-dev+3761): CS extended functionality
[04] BinTools (1.5.0-dev+3761): Low-level C/C++ Calling API
[05] SDK Tools (1.5.0-dev+3761): Source SDK Tools
[06] Regex (1.5.0-dev+3761): Provides regex natives for plugins
[07] Top Menus (1.5.0-dev+3761): Creates sorted nested menus
[08] SteamTools (0.8.2): SteamWorks for SourceMod.
[09] Socket (3.0.1): Socket extension for SourceMod
[10] Client Preferences (1.5.0-dev+3761): Saves client preference settings
[11] SQLite (1.5.0-dev+3761): SQLite Driver
[12] SDK Hooks (2.2.0): Source SDK Hooks
[13] GeoIP (1.5.0-dev+3761): Geographical IP information
[14] GeoIPCity (1.1.0): Geographical IP information
[15] Connect (1.2.0): Forward for early connection
[16] cURL Extension (1.3.0.0): cURL Extension

vodka00
02-02-2013, 02:08
Any idea why it would not load up?

edit: I can load it through rcon via sm exts load smjansson. But it does not load automatically when server restarts.

bl4nk
02-02-2013, 05:24
Do you have a plugin that uses this extension? If not, you'll have to create an autoload file for it.

rockstar269
02-03-2013, 21:45
how do i install it

vodka00
02-03-2013, 22:31
how do i install it

1. Download smjansson_2.3.1.3_binaries.zip (https://forums.alliedmods.net/attachment.php?attachmentid=105507&d=1340554215)
2. Locate cstrike/addons/sourcemod/extensions folder
3. Copy .so (Linux) or .dll (Windows) file to extensions folder.
4. Restart your server.

5. If it doesn't load automatically, you will need to load it through your server.cfg
- Open your server.cfg and enter these 3 lines...

sm exts load smjansson
exts load smjansson
exts_load smjansson

I don't know which one of these does the trick, so I have all 3 of them.

bl4nk
02-04-2013, 03:32
5. If it doesn't load automatically, you will need to load it through your server.cfg
- Open your server.cfg and enter these 3 lines...

sm exts load smjansson
exts load smjansson
exts_load smjansson

I don't know which one of these does the trick, so I have all 3 of them.

No. Just create a filed called "smjansson.autoload" and put it in your extensions folder along side the binary file. The contents don't matter, so just create a txt file and rename it.

However, it should automatically load if you have a plugin that's using this extension. If you don't have one, why are you using it?

vodka00
02-04-2013, 04:23
No. Just create a filed called "smjansson.autoload" and put it in your extensions folder along side the binary file. The contents don't matter, so just create a txt file and rename it.

However, it should automatically load if you have a plugin that's using this extension. If you don't have one, why are you using it?

I have a plugin, but for me personally the extension does not load automatically.

applemes
04-14-2013, 14:01
sm exts list.

[01] Automatic Updater (1.5.0-dev+3822): Updates SourceMod gamedata files
[02] Webternet (1.5.0-dev+3822): Extension for interacting with URLs
[03] CS Tools (1.5.0-dev+3822): CS extended functionality
[04] BinTools (1.5.0-dev+3822): Low-level C/C++ Calling API
[05] SDK Tools (1.5.0-dev+3822): Source SDK Tools
[06] Top Menus (1.5.0-dev+3822): Creates sorted nested menus
[07] Client Preferences (1.5.0-dev+3822): Saves client preference settings
[08] SQLite (1.5.0-dev+3822): SQLite Driver
[09] SDK Hooks (1.5.0-dev+3822): Source SDK Hooks
[10] GeoIP (1.5.0-dev+3822): Geographical IP information
[11] MySQL-DBI (1.5.0-dev+3822): MySQL driver implementation for DBI
[12] Regex (1.5.0-dev+3822): Provides regex natives for plugins
[13] <FAILED> file "smjansson.ext.dll": The specified module could not be found.


Help please.

Logifl3x
05-05-2013, 01:44
For some reason SMJansson doesn't automatically load for me. I have to load it each time I do a server restart.

vodka00
05-05-2013, 04:16
For some reason SMJansson doesn't automatically load for me. I have to load it each time I do a server restart.

If you are using it for store, then it does the same for me. You can just this to your server.cfg

sm exts load smjansson

Thrawn2
05-05-2013, 04:43
$ git clone https://github.com/alongubkin/store.git
Cloning into 'store'...
remote: Counting objects: 1044, done.
remote: Compressing objects: 100% (354/354), done.
remote: Total 1044 (delta 646), reused 1024 (delta 636)
Receiving objects: 100% (1044/1044), 333.46 KiB | 221 KiB/s, done.
Resolving deltas: 100% (646/646), done.

$ cd store\
$ grep -inr smjansson *
README.md:13:* [SMJansson](https://forums.alliedmods.net/showthread.php?t=184604)
It never includes smjansson anywhere, hence it's not loading.

Powerlord
05-05-2013, 14:18
For some reason SMJansson doesn't automatically load for me. I have to load it each time I do a server restart.
Create an empty file in the extensions directory with this name:
smjansson.autoload

MelonDash
06-08-2013, 08:10
Hey how do i install smjansson_2.3.1.3.zip?

And why can't i use the !shop command when i can use !gift and all that?

vodka00
06-08-2013, 12:42
Hey how do i install smjansson_2.3.1.3.zip?

And why can't i use the !shop command when i can use !gift and all that?

Drop the files into your extension folder. It doesn't load automatically with the store plugin. You can either type 'sm exts load smjansson' or create an empty smjansson.autoload file in the extensions folder.

napalm00
06-16-2013, 17:17
Thrawn, you should recompile the binaries to include the changes you've made, both the binaries here and on GitHub, for example, don't include json_load_ex().
Just throwing this out here since I found json_load_ex() to be extremely useful for checking for valid json without logging errors. Tell me if you want me to post here the Linux binary I compiled in case you're unable to compile it.

Thank you anyway for this awesome and well-documented extension :bee:

Bonnis
10-01-2013, 11:11
im havning problems to get this to work...
whys that?

vodka00
10-03-2013, 04:12
im havning problems to get this to work...
whys that?

Type 'rcon sm exts list' in console in the server and post what you got here please. You could look at post #27, it could help

neatek
12-07-2013, 05:20
okay, with what extensions i can use it?
for getting html data from my site.

wherE1997
12-16-2013, 16:22
how to instell this plugin?


sorry for my ban english

Lange
04-16-2014, 21:53
I'd love to have some updated binaries for this. I can try to compile them myself but the easy route is always nice.

Dr_Knuckles
04-27-2014, 19:40
This won't load for me, any idea why?

Thrawn2
05-24-2014, 19:20
I'd love to have some updated binaries for this. I can try to compile them myself but the easy route is always nice.Try these. They are built against the latest version of Jansson (2.6).
I did not even try running the linux version, but i suppose it works.

:bacon!:

milkcookie
06-10-2014, 02:02
um i'm using your plugin with Store plugin -(by alongub) and i'm haveing this error:
DataTables warning (table id = 'manageUsers'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
is it saying there's problem with your smjansson plugin or it's just store plugin's error?

Thrawn2
07-16-2014, 12:29
Experimental SourceMod 1.7 style includes.
The test library and plugin is also adapted and shows 106 of 106 passed tests.
Have fun.

:bacon!:

TheClassified
07-17-2014, 07:31
SMJansson wont load, can somebody help me fix this? I've put it both in sourcemod/bin and sourcemod/extensions.

Thrawn2
07-17-2014, 13:06
SMJansson wont load, can somebody help me fix this? I've put it both in sourcemod/bin and sourcemod/extensions.
You are probably not running any plugins that actually require SMJansson.
If you do, post the error messages you are getting.

:bacon!:

JaraGamer
07-22-2014, 02:52
as installed this plugin? please help

versatile_bfg
07-22-2014, 06:17
as installed this plugin? please help

You put the files out of the smjansson_2.3.1.3_binaries.zip into your addons/sourcemod/extensions/ folder.

If it doesn't auto load, create a file called smjansson.autoload in the same folder as above.

Thrawn2
07-22-2014, 11:51
If it doesn't auto load, create a file called smjansson.autoload in the same folder as above.There is no reason to do that. This extension does nothing without a plugin actually using it. And if there a plugin that is using it, it will get loaded automatically.

versatile_bfg
07-22-2014, 19:06
There is no reason to do that. This extension does nothing without a plugin actually using it. And if there a plugin that is using it, it will get loaded automatically.

Yeah I just saw other people in this thread having problems and this was a solution. So I added it there just in case.

8guawong
08-31-2014, 09:07
L 08/31/2014 - 21:02:56: [SM] Unable to load extension "smjansson.ext": cstrike/addons/sourcemod/extensions/smjansson.ext.so: invalid ELF header
L 08/31/2014 - 21:02:56: [SM] Unable to load plugin "store/store-skins.smx": Required extension "SMJansson" file("smjansson.ext") not running

ummmm how to fix this error?

Robin955
09-21-2014, 14:29
running linux tape

[09] <FAILED> file "smjansson.ext.so": /cstrike/addons/sourcemod/extensions/smjansson.ext.so: cannot open shared object file: No such file or directory
[10] Regex (1.6.2): Provides regex natives for plugins
[11] <FAILED> file "dbi.mysql.ext.so": libz.so.1: cannot open shared object file: No such file or directory

but its there * -_-

amauri_long
12-21-2014, 10:29
there's no way to create an extension for mac smjansson.ext.dylib
smjansson.ext.dll smjansson.ext.so

darkid
01-31-2015, 15:29
Could you make a mac compile?

red4911
02-27-2015, 15:56
Error ? Help

//SourceMod Batch Compiler
// by the SourceMod Dev Team


//// store-skins.sp
//
// D:\1.7.1\scripting\include\smjansson.inc(66) : error 173: 'in' is a newly res
erved keyword that may be used in the future; use a different name as an identif
ier
//
// 1 Error.
//
// Compilation Time: 0,84 sec
// ----------------------------------------

Press enter to exit ...

henri9813
03-02-2015, 06:15
Error ? Help


That should solve your problem, works for me :)

Azerja12
03-19-2015, 05:12
I am not able to get this extension to work. I've tryed all the config commands and made an empty autoload file.
I also don't know where to put the other files. Beeing the other zip file. Not the binaries. I don't know if i even need them. I've been told i don't.
I want it to work for the store plugin.

versatile_bfg
03-19-2015, 19:23
I am not able to get this extension to work. I've tryed all the config commands and made an empty autoload file.
I also don't know where to put the other files. Beeing the other zip file. Not the binaries. I don't know if i even need them. I've been told i don't.
I want it to work for the store plugin.

These ones are working on both windows and linux servers.

https://forums.alliedmods.net/showpost.php?p=2142084&postcount=35

I did have to create a autoload file as I don't have a plugin that uses this extension.

smjansson.autoload

You only need the binaries. Test that, if that doesnt work then report back with what error you are getting and what OS the server is on.

WickstonAlmighty
11-26-2015, 16:04
Still having problems loading SMJannson.

Not sure what 'file "smjannson.ext.dll" : The specified module could not be found' means.

sm exts list shows the following:

[SM] Displaying 11 extensions:
[01] Automatic Updater (1.7.3-dev+5275): Updates SourceMod gamedata files
[02] Webternet (1.7.3-dev+5275): Extension for interacting with URLs
[03] <FAILED> file "smjannson.ext.dll": The specified module could not be found.
[04] TF2 Tools (1.7.3-dev+5275): TF2 extended functionality
[05] BinTools (1.7.3-dev+5275): Low-level C/C++ Calling API
[06] SDK Hooks (1.7.3-dev+5275): Source SDK Hooks
[07] SDK Tools (1.7.3-dev+5275): Source SDK Tools
[08] Top Menus (1.7.3-dev+5275): Creates sorted nested menus
[09] Regex (1.7.3-dev+5275): Provides regex natives for plugins
[10] Client Preferences (1.7.3-dev+5275): Saves client preference settings
[11] SQLite (1.7.3-dev+5275): SQLite Driver

I have smjannson.ext.dll file in my /addons/sourcemod/extensions folder. I've also created the blank smjannson.autoload file and placed in same folder.

Can anyone please provide help? Thanks. :D

ThefatDaddy
12-22-2015, 05:11
I may be way oversimplifying this but when I checked the sm exts list results I got

[SM] Displaying 13 extensions:
[01] Automatic Updater (1.7.3-dev+5280): Updates SourceMod gamedata files
[02] Webternet (1.7.3-dev+5280): Extension for interacting with URLs
[03] SMJansson (2.6.0/1): JSON parser/writer
[04] <FAILED> file "smjannson.ext.so": /home/insurg/insurg27026/insurgency/addons/sourcemod/extensions/smjannson.ext.so: cannot open shared object file: No such file or directory
[05] Top Menus (1.7.3-dev+5280): Creates sorted nested menus
[06] Client Preferences (1.7.3-dev+5280): Saves client preference settings
[07] SQLite (1.7.3-dev+5280): SQLite Driver
[08] SDK Tools (1.7.3-dev+5280): Source SDK Tools
[09] BinTools (1.7.3-dev+5280): Low-level C/C++ Calling API
[10] Regex (1.7.3-dev+5280): Provides regex natives for plugins
[11] SDK Hooks (1.7.3-dev+5280): Source SDK Hooks
[12] GeoIP (1.7.3-dev+5280): Geographical IP information
[13] MySQL-DBI (1.7.3-dev+5280): MySQL driver implementation for DBISo I changed the spelling of the file to match what is being called for from smjansson.ext.so to smjannson.ext.so and everything worked. I also have the original file [smjansson.ext.so] in my /extensions directory.

[SM] Displaying 12 extensions:
[01] Automatic Updater (1.7.3-dev+5280): Updates SourceMod gamedata files
[02] Webternet (1.7.3-dev+5280): Extension for interacting with URLs
[03] Top Menus (1.7.3-dev+5280): Creates sorted nested menus
[04] Client Preferences (1.7.3-dev+5280): Saves client preference settings
[05] SQLite (1.7.3-dev+5280): SQLite Driver
[06] SDK Tools (1.7.3-dev+5280): Source SDK Tools
[07] BinTools (1.7.3-dev+5280): Low-level C/C++ Calling API
[08] Regex (1.7.3-dev+5280): Provides regex natives for plugins
[09] SDK Hooks (1.7.3-dev+5280): Source SDK Hooks
[10] SMJansson (2.6.0/1): JSON parser/writer
[11] GeoIP (1.7.3-dev+5280): Geographical IP information
[12] MySQL-DBI (1.7.3-dev+5280): MySQL driver implementation for DBI

asherkin
12-24-2015, 05:12
The spelling in the include file in the repo is correct, the problem is in whatever plugin you have requiring it.

dildoughy
04-07-2016, 18:04
I have no idea what I'm supposed to do with the pawn and sdk folders included in the 2.3.1.3 .zip release, or where .cpp and .h files are supposed to go (I've never seen them before).

asherkin
04-07-2016, 18:40
That's the source code, you want the other attachment.

Dudunik
04-26-2016, 14:47
Hi,

I have a problem with use smjannson extension.

I compiled plugin with this extension and all is ok (without any problems) but when i start server and check what plugins are loaded then i see <Failed> in my compiled plugin and after run command "sm plugins refresh" i see a error
Native "json_array_append_new" was not found.

How I can fix this problem? I used version of smjansson.inc from first post (https://raw.github.com/thraaawn/SMJansson/master/pawn/scripting/include/smjansson.inc).

Legendoniance
05-07-2016, 12:38
Hi can I check if there is a mac version for it? Can someone come up with one please? :(

switz213
05-11-2016, 00:59
Can I get an array from a json object via json_object_get? If I want to append/create an array beneath a json object, would this code work?


Handle jsonObj = json_object();
Handle jsonArr = json_object_get(g_globalJSONObj, "hi");

// if array doesn't exist, create it
if (jsonArr == INVALID_HANDLE) {
jsonArr = json_array();
}

json_object_set_new(jsonObj, "foo", json_integer(1));

json_array_append_new(jsonArr, jsonObj);

json_object_set(g_globalJSONObj, "hi", jsonArr);
}


Should json_object_set be json_object_set_new or would that close the handle on the existing jsonArr?

What I hope to happen in data:

{}
{ "hi": [] }
{ "hi": [{"foo": 1}] }

WildCard65
05-11-2016, 06:42
Ya, you can put JSON Arrays/Objects inside of another JSON Array/Object, example:


{
"array1": [
{
}
]
}

What above example has is a json object containing a json array at key "array1" which contains a json object.

Jon4ik
06-19-2016, 06:01
Hi. Why doesn't works json_object_get_int? She always returns 0.

Legendoniance
07-24-2016, 09:37
Hi, I need this as a dependency for another plugin, but I can't get it to work on my server. I am running OS X (I know it's not steam-approved), but is there any way to port it or make it work on OS X?

mushi88
09-18-2016, 12:37
Fails to load on server start, reloading doesn't help, as it fails again.

[SM] Unable to load extension "smjansson.ext": error code 0000007e

Spirit_12
09-18-2016, 16:09
Fails to load on server start, reloading doesn't help, as it fails again.

[SM] Unable to load extension "smjansson.ext": error code 0000007e

Windows or Linux?

psychonic
09-18-2016, 17:09
Seems like probably Windows, where 0000007e would be Module Not Found.

The extension may have been dynamically linked to the CRT and require a version of the Microsoft C++ Redistributable installed. A guess based on project file is has for Jansson would be the 2010 version (32-bit). (The extension itself uses CMake, so project gets generated depending on what VS version's env you're in)

2010 https://www.microsoft.com/en-us/download/details.aspx?id=5555
2010 SP1 https://www.microsoft.com/en-us/download/details.aspx?id=8328

venon
11-03-2016, 14:48
hey
can you someone help me ? were i put al folder
sorry im new on confgs and sory for my ba english

TheSupremePatriot
12-04-2016, 20:29
It says its missing smjansson.ext the zip did NOT contain the file being mentioned. What do I do?

mlov420
08-14-2017, 13:48
Getting error code 000000c1 when attempting to use SMJansson on my Windows servers.



L 08/14/2017 - 12:39:42: [SM] Unable to load extension "smjansson.ext": error code 000000c1



I have tried downloading the version from this thread as well as the most recent one on his github. Neither will load. Was testing on a relatively clean server. Brand new MM and SM install. Extension simply won't load. No other errors listed. Any ideas?

OcC
04-07-2019, 10:47
Work on CS:S ?

S1ncer3ly
05-01-2021, 15:34
Try these. They are built against the latest version of Jansson (2.6).
I did not even try running the linux version, but i suppose it works.

:bacon!:
bro please help me where to put sdk files ? just started the server idk how to install it thankyou

JmWarrior
12-07-2023, 19:39
I don't understand how to install this, and it makes 0 sense whatsoever.

psychpayload
01-04-2024, 04:07
when im trying to load the plugins i get an error that said bad header heres what i ran: sm plugins load smjansson.ext.so

liketask
01-26-2024, 07:16
The latest SMJansson build with a memory leak fix from bottiger1 :)
It was built on Debian GNU/Linux 11 x86_64 (kernel: 5.10.0-21-amd64) for Sourcemod 1.11
Source code: https://github.com/davenonymous/SMJansson

liketask
01-26-2024, 07:22
when im trying to load the plugins i get an error that said bad header heres what i ran: sm plugins load smjansson.ext.so
smjansson.ext.so is an extension, not a plugin. Use sm exts load if you want to load extensions from the console

jjambo789
02-20-2024, 02:25
smjansson.ext.so is an extension, not a plugin. Use sm exts load if you want to load extensions from the console

Windows version? please...

Spirit_12
02-20-2024, 18:31
The latest SMJansson build with a memory leak fix from bottiger1 :)
It was built on Debian GNU/Linux 11 x86_64 (kernel: 5.10.0-21-amd64) for Sourcemod 1.11

Can you provide source files. Otherwise your attachment will get pulled.

liketask
02-20-2024, 21:22
Can you provide source files. Otherwise your attachment will get pulled.

But the link to the sources (github repository) is literally in the first topic post.
https://github.com/davenonymous/SMJansson

Spirit_12
02-20-2024, 22:03
But the link to the sources (github repository) is literally in the first topic post.
https://github.com/davenonymous/SMJansson

"The latest SMJansson build with a memory leak fix from bottiger1 "

Not the original author unless the person uses different aliases.