This extension adds serialization functionality to sourcemod. Not only JSON, but XML and binary too! It uses the C++ library Cereal.
Both JSON and XML archives can accept any primitive type, while binary can only accept integers.
I ensured that the include file was properly documented, so make sure to take a look!
Code:
char str[] = "CMake > AMBuild";
// You can also use the Xml_Archive and Binary_Archive functions
JsonArchive_SetString( 0, str ); // index 0
JsonArchive_SetFloat( 1, 3.4 ); // index 1
JsonArchive_SetInt( 2, 3.4 ); // index 2
char szFileName[512];
BuildPath( Path_SM, szFileName, sizeof( szFileName ), "data/example.json" )
JsonArchive_Serialize( szFileName );
JsonArchive_Deserialize( szFileName );
char szBuffer[128];
JsonArchive_GetString( 0, szBuffer, sizeof( szBuffer ) );
float flVal = JsonArchive_GetFloat( 1 );
int iVal = JsonArchive_GetNumber( 2 );
Source:
https://github.com/Code4Cookie/SM-Cereal