# JSON feeder to provide entire json object as string

**URL:** <https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797>\
**Category:** Gatling (Open-Source)\
**Tags:** gatling-academy\
**Created:** [April 3, 2023, 9:43am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797 "2023-04-03T09:43:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![partheeban](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@partheeban](https://community.gatling.io/u/partheeban)\
**Post date:** [April 3, 2023, 9:43am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/1 "2023-04-03T09:43:24Z")

</div>

I have an following json array.  
[  
{  
“timestamp”: “\<\>”,  
“restconf\_path”: “/devices/device=\<\>/interfaces/interface=Port-Channel31/state/admin-status”,  
“schema\_path”: “/interfaces/interface/state/admin-status”,  
“target”: “\<\>”,  
“val”: {  
“string\_val”: “UP”  
}  
},  
{  
“timestamp”: “\<\>”,  
“restconf\_path”: “/devices/device=\<\>/network-instances/network-instance=default/protocols/protocol=BFD,BFD/bfd/micro-bfd-sessions/micro-bfd-session=Port-Channel31/state/session-state”,  
“schema\_path”: “/network-instances/network-instance/protocols/protocol/bfd/micro-bfd-sessions/micro-bfd-session/state/session-state”,  
“target”: “\<\>”,  
“val”: {  
“string\_val”: “UP”  
}  
}  
]

I am reading this JSON using json feeder as follows.  
FeederBuilder feederJson = jsonFile(“messages.json”) .circular();

how can i get json object as single String in Java, instead of MAP.

Kindly provide suggestion.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [April 3, 2023, 9:59am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/2 "2023-04-03T09:59:22Z")

</div>

Not sure that’s the right way.  
You should maybe use a simple CSV feeder where each entry is JSON encoded in Base64 (use transform to decode)

---

<div class="post-metadata">

**Author:** ![sbrevet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/sbrevet/32/830_2.png) [@sbrevet](https://community.gatling.io/u/sbrevet)\
**Post date:** [April 3, 2023, 10:14am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/3 "2023-04-03T10:14:39Z")

</div>

The whole purpose of the feeder is to create this map…

So, if your value is the whole object, you’ll have to make the indirection.

```json
[
  {
    "jsonValue" : {
      // your actual first value
    }
  }, {
    "jsonValue" : {
      // your actual second value
    }
  }
]

```

Here, the `jsonValue` will be the name of the session variable.

Cheers!

---

<div class="post-metadata">

**Author:** ![partheeban](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@partheeban](https://community.gatling.io/u/partheeban)\
**Post date:** [April 3, 2023, 11:03am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/4 "2023-04-03T11:03:15Z")

</div>

Thanks @sbrevet . I modified the json and tried to fetch ’ session.getMap(“jsonvalue”).toString()’ . But still the nested json is received as MAP (val=Map(string\_val → UP)).  
How can I receive nested json also as JSON

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [April 3, 2023, 12:01pm UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/5 "2023-04-03T12:01:32Z")

</div>

> **[Expression Language](https://gatling.io/docs/gatling/reference/current/core/session/el/#built-in-functions)**
>
> How to use Gatling Expression Language to compute dynamic parameters based on Session data using a simple text templating engine

```auto
// properly formats into a JSON value (wrap Strings with double quotes, deal with null)
"#{foo.jsonStringify()}"

```

---

<div class="post-metadata">

**Author:** ![partheeban](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@partheeban](https://community.gatling.io/u/partheeban)\
**Post date:** [April 4, 2023, 6:32am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/6 "2023-04-04T06:32:32Z")

</div>

I am accessing the value inside a function, so I am using Session. I guess inside session we cannot use EL. What is correct way to access the json.

```java
 .exec(session -> {
  String message = replaceFqdn(session.getString("fqdn"), session.getMap("jsonValue").toString());
  Session newSession = session.set("message", message);
  return newSession;
})

```

I am new to gatling, so Kindly ignore if I did any basic mistakes

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [April 4, 2023, 8:22am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/7 "2023-04-04T08:22:09Z")

</div>

> JSON feeder to provide entire json object as string

The `jsonFile` feeder is meant to produce JSON objects.  
If coding some workaround to turn JSON objects back into Strings is out of your reach, I really think you should reconsider using `jsonFile`.

As I explained above, you should encode each JSON object in Base64 so they fit into a CSV line, use a `csv` feeder and use `transform` on this feeder to decode the Base64 string into JSON ones.

---

<div class="post-metadata">

**Author:** ![partheeban](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@partheeban](https://community.gatling.io/u/partheeban)\
**Post date:** [April 4, 2023, 8:40am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/8 "2023-04-04T08:40:52Z")

</div>

thanks. I will try with csv.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/2X/b/b148e0742de35c6280726cabf3ecd3de2d320f63.png) [@system](https://community.gatling.io/u/system)\
**Post date:** [May 4, 2023, 8:41am UTC](https://community.gatling.io/t/json-feeder-to-provide-entire-json-object-as-string/7797/9 "2023-05-04T08:41:34Z")

</div>

Closed on May 4, 2023, 8:41am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
