Hello,
On 18/09/2023 10:27, Jens Popp wrote:
Method now returns the content of Json Arrays, if it is specified in Json Path
as String. The start and end character is a square bracket.
Any complex object in the array is returned as Json, so that you might get
Arrays of Array or objects. Only recommended for Arrays
of simple types (e.g., String or int) which will be returned as CSV String.
---
src/sample.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/sample.c b/src/sample.c
index 07c881dcf..ecc4a961d 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -4159,8 +4159,16 @@ static int sample_conv_json_query(const struct arg
*args, struct sample *smp, vo
return 1;
}
- case MJSON_TOK_NULL:
case MJSON_TOK_ARRAY:
+ // We copy the complete array, including square
brackets into the return buffer
+ // result looks like:
["manage-account","manage-account-links","view-profile"]
+ strncpy( trash->area, token, token_size);
+ trash->data = token_size;
+ trash->size = token_size;
+ smp->data.u.str = *trash;
+ smp->data.type = SMP_T_STR;
+ return 1;
+ case MJSON_TOK_NULL:
case MJSON_TOK_OBJECT:
/* We cannot handle these. */
return 0;
--
2.39.3
[X]
You might want to use the b_putblk function instead of strncpy since you
don't manage the case where you don't have enough space in the trash
buffer. The trash->size member should never be changed as well since it
represents the buffer size, not the number of bytes written in it.
Please update the "json_query" documentation as well.
Thanks
RĂ©mi LB