I want to access the the below JSON payload :
[
{
"ApplicantContactDetail": [
{
"ApplicantBaseDetails": {
"CATEGORY": "P",
"ULN": "1265847478"
} }
]
}
]
and need output as
{
"Number":2,
"Data":
{
"ResidencyCode":"CATEGORY"
}
}
i need to map CATEGORY in the output from liquid template, may i know the correct syntax for this to achieve.
Related
I want to create a report using Jaspersoft Studio with a json file as datasource. I want to select some fields from this json and also a substring of the original json. This should be done by jsonql.
First, an example with the "JSON language" in JasperSoftStudio:
gives the following result:
This is exactly what I want to have, the delivery note number as a field, and the barcodes as an array of objects / json substring.
What I am not able to do is, to achieve this with jsonql. The following query
gives the result
The following json was used for this example
{
"tour": {
"shipments": [
{
"containers": [
{
"boxes": [
{
"customerModule": "DEFG",
"deliveryDateTime": "2022-04-25 11:49:24.834000",
"boxNumber": 2
},
{
"customerModule": "ABCD",
"deliveryDateTime": "2022-04-25 11:50:24.810000",
"boxNumber": 1
}
],
"licensePlate": "123"
}
],
"deliveryNoteNumber": "6785000",
"barcodes": [
{
"content": "barcode_01_04"
},
{
"content": "barcode_03_04"
},
{
"content": "barcode_04_04"
}
]
},
{
"containers": [
{
"boxes": [
{
"customerModule": "ZXYV",
"deliveryDateTime": "2022-04-25 11:51:24.834000",
"boxNumber": 1
},
{
"customerModule": "UHGI",
"deliveryDateTime": "2022-04-25 11:52:24.834000",
"boxNumber": 2
}
],
"licensePlate": "987"
}
],
"deliveryNoteNumber": "6785001",
"barcodes": [
{
"content": "Barcode_01_04"
},
{
"content": "Barcode_02_04"
},
{
"content": "Barcode_04_04"
}
]
}
],
"handlingDateTime": "2022-04-25 11:50:24.883000"
}
I tried to use this documentation, but I could not get it working.
The JSONQL data source doesn't properly convert arrays to Strings for some reason.
What you can do is change the barcodes field from java.lang.String to java.lang.Object. You can do that by clicking Edit in the Fields tab and changing the Class Type for the field.
With java.lang.Object as field type, the field value will be the underlying JSON (Jackson) model array object. You can do $F{barcodes}.toString() if you need to explicitly convert it to a String in an expression.
I am using Gatling to test an API that accepts a json body like below:
{
"data": {
"fields": [
{
"rank": 1
},
{
"name": "Jack"
}
]
}
}
I have created a file feeder.json that contains array of json objects like above.
Below is the feeder.json
[
{
"data": {
"fields": [
{
"rank": 1
},
{
"name": "Jack"
}
]
}
}
]
I have created another file template.txt that contains the template of above json.
Below is the template.txt
{
"data": {
"fields": [
{
"rank": ${data.fields[0].rank} //this is not working
},
{
"name": "Jack"
}
]
}
}
val jsonFeeder = jsonFile("feeder.json").circular
scenario("Test scenario")
.feed(jsonFeeder)
.exec(http("API call test")
.post("/data")
.body(ElFileBody("template.txt"))
.asJson
.check(status is 200))
I am feeding the feeder.json and also sending json body from template.json. The 'rank' property values should get set from feeder into the json body. But I am getting an error 'Map named 'data' does not contain key 'fields[0]'. Stuck with this.
Access by index syntax uses parens, not square braces.
#{data.fields(0).rank}
Why is the json code wrong? I know I can have multi key in XML, but it seem that json doesn't allow.
{
"BackupSettings": {
"Setting":
{
"id": "34345"
},
"Setting": {
"id": "16454"
}
}
}
Indeed, keys within an object are required to be unique in JSON. The canonical way of expressing your data in JSON would be to use an array. It could look something like the following:
{
"BackupSettings": {
"Settings": [
{
"id": "34345"
},
{
"id": "16454"
}
]
}
}
Or even:
{
"BackupSettings": [
{
"id": "34345"
},
{
"id": "16454"
}
]
}
I have JSON schema as follows
{
"type":"object",
"$schema": "http://json-schema.org/draft-03/schema",
"required":false,
"properties":{
"example": {
"type":"object",
"required":false,
"properties":{
"age": {
"type":"number",
"required":false
}
}
}
}
}
Which is saved as ExampleResponse.jss .
Using 'jsonschema2pojo' maven plugin, i generated POJO class from this schema. Using this class I am trying to create a JSON response and the expected output response should be
{
"example":{
"age":68
}
}
Since the Generated POJO is
class Example { ..... }
output Response i am getting is
{
"Example":{
"age":68
}
}
How I can achieve desired response in which i have lower case 'example' word.
I have the following JSON payload. I would like to extract the value "value_for_key_attribute_Y" using JSON path expression in a generic manner (i.e. without hard coding any array values like [1]) Any ideas ?
{
"requests":[
{
"event":[
{
"parameter":"parameter_key_A",
"event":"event_key_A",
}
],
"data":[
{
"id":"id_xyz",
"payload_data":[
{
"key":"key_attribute_X",
"value":"value_for_key_attribute_X",
},
{
"key":"key_attribute_Y",
"value":"value_for_key_attribute_Y",
}
]
}
]
}
]
}
Something like this should work for you.
$.requests[*].data[*].payload_data[?(#.key_path == 'key_attribute_Y')].value