I'm am not sure that this json is formatted correctly can someone tell me what is wrong with the formatting?
{"response": 1,
"data": { "events": [
{
"placeTitle":"Griffwood Dr",
"placeAddress": "Canonsburg, , ",
"downCount": "0",
"time": "2015-01-01 06:47:28 UTC",
"nameOfHost": "Tyler Rice",
"event_id": "21",
"userresponse": "0",
"people_down": []
},
]
}}
You need to remove the comma if you are not going to have another object:
{"response": 1,
"data": { "events": [
{
"placeTitle":"Griffwood Dr",
"placeAddress": "Canonsburg, , ",
"downCount": "0",
"time": "2015-01-01 06:47:28 UTC",
"nameOfHost": "Tyler Rice",
"event_id": "21",
"userresponse": "0",
"people_down": []
}
]
}}
For future, you can use a JSON parser such as this one.
Remove the extra comma after the object within the array. Since there is only one object in the array there is no need to use the comma delimiter, which would normally separate objects.
{
"placeTitle":"Griffwood Dr",
"placeAddress": "Canonsburg, , ",
"downCount": "0",
"time": "2015-01-01 06:47:28 UTC",
"nameOfHost": "Tyler Rice",
"event_id": "21",
"userresponse": "0",
"people_down": []
}, //remove this comma
Related
I have the following json:
{
"configs": [
{
"configName": "config1",
"configTarget": "/app/appsettings.json",
"uid": "0",
"gid": "0",
"mode": 292
},
{
"configName": "config2",
"configTarget": "/app/appsettings.json",
"uid": "0",
"gid": "0",
"mode": 292
}
]
}
And I want to change the value of configName which currently has a value of config1.
I know I can do
.configs[0].configName = "foo"
But I don't want to rely on the position in the array of the one I want to change, how can I find that and then set the value?
.configs |= map(select(.configName == "config1").configName |= "foo-bar")
Update .configs (|=)
Map over each object in the array
Filter (select()) the desired object
Update .configName
Result:
{
"configs": [
{
"configName": "foo-bar",
"configTarget": "/app/appsettings.json",
"uid": "0",
"gid": "0",
"mode": 292
},
{
"configName": "config2",
"configTarget": "/app/appsettings.json",
"uid": "0",
"gid": "0",
"mode": 292
}
]
}
Demo
Error: Parse error on line 12:
..."disliked": "true"}, { "liked": "true"
----------------------^
Expecting 'EOF', got ','
Json:
{
"liked": "true",
"user_id": "101",
"video_end_type": "3",
"minutes_played": "3",
"video_id": "101",
"geo_cd": "AP",
"channel_id": "11",
"creator_id": "101",
"timestamp": "07/05/2019 01:36:35",
"disliked": "true"
}, {
"liked": "true",
"user_id": "102",
"video_end_type": "null",
"minutes_played": "4",
"video_id": "102",
"geo_cd": "AP",
"channel_id": "12",
"creator_id": "102",
"timestamp": "15/04/2019 17:04:00",
"disliked": "true"
}
You have an invalid JSON structure. There are two root elements and based on your JSON structure it appears that this is supposed to be a collection. Wrap your JSON structure in [] to make it a collection.
[
{
"liked":"true",
"user_id":"101",
"video_end_type":"3",
"minutes_played":"3",
"video_id":"101",
"geo_cd":"AP",
"channel_id":"11",
"creator_id":"101",
"timestamp":"07/05/2019 01:36:35",
"disliked":"true"
},
{
"liked":"true",
"user_id":"102",
"video_end_type":"null",
"minutes_played":"4",
"video_id":"102",
"geo_cd":"AP",
"channel_id":"12",
"creator_id":"102",
"timestamp":"15/04/2019 17:04:00",
"disliked":"true"
}
]
I've got the response from HTTP GET request as JSON file and I want to use that JSON and pass it to the next HTTP request. I got the following response data
{
"apiInfo": {
"id": "23143",
"name": "bookkeeping",
"state": "used",
"data": "15893712000000"
},
"apiDetails": [
{
"bookName": "abc",
"state": "old",
"noOfTimesUsed": "53"
"additionalParam"{
"name": "abc",
"id": "123"
}
},
{
"bookName": "def",
"state": "new",
"noOfTimesUsed": "5",
"action": "keep"
"additionalParam"{
"name": "def",
"id": "456"
}
},
{
"bookName": "xyz",
"state": "avg",
"noOfTimesUsed": "23"
"additionalParam"{
"name": "ghi",
"id": "789"
}
},
{
"bookName": "pqr",
"state": "old",
"noOfTimesUsed": "75",
"action": "discard"
"additionalParam"{
"name": "jkl",
"id": "012"
}
}
]
}
I want to use "apiInfo" & "apiDetails" part from the JSON response and manipulate its data. As you can notice, some array field have attribute "action" in it and some one doesn't. I want to make sure all the field in the array have this data and is assigned as ' "action":"keep" '. Also, I want to add "id" from apiInfo & "name" from additionalParams from apiDetails itself. The end result I want is somewhat like this
"apiDetails": [
{
"id": "23143",
"bookName": "abc",
"state": "old",
"noOfTimesUsed": "53",
"action": "keep",
"name":"abc"
},
{
"id": "23143",
"bookName": "def",
"state": "new",
"noOfTimesUsed": "5",
"action": "keep",
"name":"def"
},
{
"id": "23143",
"bookName": "xyz",
"state": "avg",
"noOfTimesUsed": "23",
"action": "keep",
"name":"ghi"
},
{
"id": "23143",
"bookName": "pqr",
"state": "old",
"noOfTimesUsed": "75",
"action": "keep",
"name":"jkl"
}
]
I've been trying to use JSR223 sampler and have been struggling with it. It's bit complicated and I need help. P.S.: I've tried using javascript code to manipulate the results as desired but have been unsuccessful.
Please help.
Thanks, Sid
Add JSR223 PostProcessor as a child of the request which returns the above JSON
Put the following code into "Script" area:
def apiDetails = new groovy.json.JsonSlurper().parse(prev.getResponseData()).apiDetails
apiDetails.each { apiDetail ->
apiDetail.put('action', 'keep')
}
vars.put('request', new groovy.json.JsonBuilder(apidetails: apiDetails.collect()).toPrettyString())
That's it, you should be able to refer the generated request as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
I have a JSON object which has 100000 records. I want a select a record which has specific value to the one of the key
Eg:
[{
"name": "bindu",
"age": "24",
"qualification": "b.tech"
},
{
"name": "naveen",
"age": "23",
"qualification": "b.tech"
},
{
"name": "parvathi",
"age": "23",
"qualification": "m.tech"
},
{
"name": "bindu s",
"status": "married"
},
{
"name": "naveen k",
"status": "unmarried"
}]
now I want to combine the records which are having the name with 'bindu' and 'bindu s. We can achieve this by iterating on the JSON object but since the size is more it is taking more time. Is there any way to make this easy.
I want the output like
[{
"name": "bindu",
"age": "24",
"qualification": "b.tech",
"status": "married"
},
{
"name": "naveen",
"age": "23",
"qualification": "b.tech",
"status": "unmarried"
},
{
"name": "parvathi",
"age": "23",
"qualification": "m.tech"
"status": ""
},
This will rename and merge your objects by first name.
jq 'map(.name |= split(" ")[0]) | group_by(.name) | map(add)'
I'm using the rest API to create an in person signing session from salesforce. My envelope creation json is like this:
{
"documents": [{
"documentBase64": "'+base64EncodedDocToSign+'",
"documentId": "1",
"fileExtension": "pdf",
"name": "contract.pdf"
}
],
"emailSubject": "Please Sign",
"recipients": {
"inPersonSigners": [{
"email": "some#gsome.com",
"name": "Luis",
"hostEmail": "some#gsome.com",
"hostName": "Luis",
"signerEmail": "other#gother.com",
"signerName": "Charles",
"recipientId": "1",
"tabs": {
"signHereTabs": [{
"anchorString": "s1",
"anchorXOffset": "0",
"anchorYOffset": "0",
"anchorIgnoreIfNotPresent": "false",
"anchorUnits": "inches"
}
]
},
"routingOrder": "1",
"clientUserId": "1000",
"embeddedRecipientStartURL": "SIGN_AT_DOCUSIGN",
}
]
},
"status": "sent"
}
The next step would be for the object to be tracked using Connect. Connect is properly configured for the object and works if I "Sign with Docusign" or use a custom button.
I understand I must change the json to include the DSFSSourceObjectId custom field, with value equal to the Id of the object that is originating the request, but if I try to get a customField in there the json is not properly formatted anymore.
I tried adding the customField like:
...
}
]
},
"customFields": [
{
"Name": "DSFSSourceObjectId",
"Value": "' + objectId + '"
}
],
"status": "sent"
}
Is this viable?
I got this working adding the following to the JSON:
"customFields": {
"textCustomFields": [{
"value": "salesforceId",
"required": "false",
"show": "false",
"name": "DSFSSourceObjectId"
}
]
},