Key-Value Pairs and numeric fields


#1 nimaimalle

From this example, in the docs: Name=Mike, Weight=64, Age=24, Pet=dog, Height=172

The sample shows accessing the fields like this, effectively casting certain values to integers: if ( integer($Weight) > integer($Height) - 100 )

However, I am using parse_kvp on data that I don't necessarily know the format of, then converting the data into JSON. In JSON, all of the values are quoted, including numeric ones. I need the numeric fields to be unquoted in JSON.

Is there a way to iterate through all fields in an Exec statement? I could test for numeric values and reassign them, casting to integer or float (but I don't think there's a float type)

I also thought about transforming the JSON string with s/"([0-9.]+)"/$1/g but this sort of regex is not yet supported in nxlog.

Any suggestions how to take Name=Mike, Weight=64, Age=24, Pet=dog, Height=172.5 and get the following JSON without referencing the fields by name? {"Name":"Mike","Weight":64,"Age":24,"Pet":"dog","Height":172.5}

(no quotes around numbers)

#2 nimaimalle
#1 nimaimalle
From this example, in the docs: Name=Mike, Weight=64, Age=24, Pet=dog, Height=172 The sample shows accessing the fields like this, effectively casting certain values to integers: if ( integer($Weight) > integer($Height) - 100 ) However, I am using parse_kvp on data that I don't necessarily know the format of, then converting the data into JSON. In JSON, all of the values are quoted, including numeric ones. I need the numeric fields to be unquoted in JSON. Is there a way to iterate through all fields in an Exec statement? I could test for numeric values and reassign them, casting to integer or float (but I don't think there's a float type) I also thought about transforming the JSON string with s/"([0-9.]+)"/$1/g but this sort of regex is not yet supported in nxlog. Any suggestions how to take Name=Mike, Weight=64, Age=24, Pet=dog, Height=172.5 and get the following JSON without referencing the fields by name? {"Name":"Mike","Weight":64,"Age":24,"Pet":"dog","Height":172.5} (no quotes around numbers)

Maybe something like the QuoteMethod directive could work?

Feels like QuoteMethod needs a "NonNumeric" option which will only quote values that aren't valid numeric expressions:

Regexp to test if a string is a valid numeric value, including optional decimal points and exponent.

^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$