670
Views
3
Comments
Manipulate Dynamic JSON
Question

Hi everyone,

I hope you are doing well.

I am doing a REST call directly to elasticsearch 7. To filter the results (by action, espace_name, username and timestamp), I need to send a body like this one :

{
"from": 0,
    "size": 200,
     "sort" : { "Instant" : "desc" },
      "query": {
      "bool": {
          "must": [
            { "match": { "Action":"GetList" }},
            { "match": { "Espace_Name":"Tarefas" }},   

            { "match": { "Username":"P02154" }},

            {"range" : {
            "Instant" : {
                "gte" : "2019-11-14T14:09:00.476565Z",
                "lte" : "2019-11-14T14:10:00.758346Z"
            }
        }
      }
          ]
        }
}
}


However, because the "match" attributes are changing dynamically, according to the filter I want to implement, I am having some troubles building a compatible structure.

Can someone give me an idea how to solve this issue?


Thank you.

2021-06-09 13-39-18
Agno Silveira
 
MVP

Hello Joana,

You can create a local object, after that you manipulate your object/list, and after you must convert in JSON.

Example:

Regards.

UserImage.jpg
Joana Lourenço Tavares

Hi Agno, 

Thank you.

I am already doing a serialization. 

The problem is that I cannot build a structure that meets the requirements because "match" attribute depends on the filter and I cannot have two different attributes with the same name in JSON.

2023-02-20 18-27-41
Gonçalo Soares

Your best bet is the ArdoJson Forge component:

  • Create a single Structure with two attributes: "key" and "value", of type Text, to use inside the "match" field, and change the "match" field to be of type "List".
  • Then, in the OnBeforeRequest of your REST integration, call the JSON_Objectify to convert all "match" fields into objects with dynamic names.


See the example below.

I'm not sure if I got the JSON Path correct - you'll probably need to play around with an online evaluator to get it right.



Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.