Libraries: MQL4/5-JsonLib - page 2

 
hini #:
how?
template <typename T>
bool IsInteger( const T s )
{
//  return((s != '.') && (s != 'e') && (s != 'E'));
  return((s != '.') && (s <= '9'));
}

#define NUM_FORMAT 1 // https://www.mql5.com/en/forum/502194#comment_58768363
bool IsIntegerFast( const string &num_str )
{
  const int Size = StringLen(num_str) - NUM_FORMAT;  
  
  for (int i = NUM_FORMAT; i < Size; i++)
    if (!IsInteger(num_str[i]))
      return(false);
  
  return(true);
}

bool IsIntegerSlow( const string &num_str )
{
  // https://www.mql5.com/en/forum/502194#comment_58768032
  return(StringFind(num_str, ".") < 0 && StringFind(num_str, "e") < 0 && StringFind(num_str, "E") < 0);
}

void OnStart()
{
  string Str = "1.23";
  
  Print(IsIntegerFast(Str));
  Print(IsIntegerSlow(Str));
}
 
if(ArrayResize(m_arr, s + 1) > 0) m_arr[s] = v;
if(ArrayResize(m_arr, s + 1, 1e3) > 0) m_arr[s] = v;
 
fxsaber #:
  string Str = "123e"; //StringLen(num_str) - NUM_FORMAT == 3
  
  Print(IsIntegerFast(Str)); //true
  Print(IsIntegerSlow(Str));//false
 
fxsaber #:
thanks.
 
hini #:
"123e" - integer.
"123." - integer.
 
fxsaber #:
These are not standard JSON integers.
 
hini #:
These are not standard JSON integers.
That's why a macro with a value of one was created.
 
hini #:

MT5 exports JSON in UTF16 format, while this library exports files in UTF8 format. The order may differ, but the content is the same.

The JSON file path should be placed in `MQL5/Files/`.

Thanks for the example!
 
fxsaber #:
There are many JSON libraries on this resource. Which one is the fastest?

Comparison of this library with the old JASon, with a data file of 100 MB

2025.12.20 12:47:28.234    jason_bench (EURUSD,H1)    JASon Example Deserialization:
2025.12.20 12:47:50.302    jason_bench (EURUSD,H1)    Deserialize 107652093 bytes JSON in 22020713 microseconds. 
2025.12.20 12:47:50.302    jason_bench (EURUSD,H1)    Check value = Richard Sullivan
2025.12.20 12:47:50.302    jason_bench (EURUSD,H1)    Terminal memory used =2023, MQL memory used = 1958 MB

2025.12.20 12:47:53.007    JsonLib_bench (EURUSD,H1)    ====== MQL5 JSON Library - Bench parsing ======
2025.12.20 12:47:54.601    JsonLib_bench (EURUSD,H1)    Deserialize 107652093 characters JSON in 1461365 microseconds. 
2025.12.20 12:47:54.601    JsonLib_bench (EURUSD,H1)    Check value = Richard Sullivan
2025.12.20 12:47:54.601    JsonLib_bench (EURUSD,H1)    Terminal memory used =4987, MQL memory used = 4879 MB

This one is a lot faster but is using 2.5 times more memory. 

JSON Serialization and Deserialization (native MQL)
JSON Serialization and Deserialization (native MQL)
  • 2015.10.12
  • www.mql5.com
Serialization and deserialization of JSON protocol. The code is ported from a high-speed С++ library.
 
Alain Verleyen #:
but is using 2.5 times more memory. 
Thank you for testing. This library has a streaming JSON parsing feature. Using this feature, memory usage should be minimal, but I'm not sure if the speed will decrease, as I haven't conducted thorough testing.