Search JSON file bash - json

I have following JSON file and would like to extract part of it:
{
"expand": "names,schema",
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"fields": {
"aggregateprogress": {
"progress": 0,
"total": 0
},
"aggregatetimeestimate": null,
"aggregatetimeoriginalestimate": null,
"aggregatetimespent": null,
"assignee": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user",
"emailAddress": "user#company.com",
"key": "user",
"name": "user",
"self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
"timeZone": "Europe/Belgrade"
},
"components": [],
"created": "2018-03-06T21:24:41.000+0000",
"creator": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user",
"emailAddress": "user#company.com",
"key": "user",
"name": "user",
"self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
"timeZone": "Europe/Belgrade"
},
"customfield_10000": null,
"customfield_10001": null,
"customfield_10002": null,
"customfield_10004": "0|i00uta:",
"customfield_10005": null,
"customfield_10006": null,
"customfield_10100": null,
"customfield_10101": [],
"customfield_10102": null,
"customfield_10103": null,
"customfield_10107": {
"id": "10400",
"self": "https://jira.corp.company.com/rest/api/2/customFieldOption/10400",
"value": "Hentsu Internal"
},
"customfield_10108": null,
"customfield_10200": null,
"customfield_10201": "2018-03-06",
"customfield_10202": "2018-03-06",
"customfield_10203": null,
"customfield_10204": null,
"customfield_10205": null,
"customfield_10206": null,
"customfield_10300": "com.atlassian.servicedesk.plugins.approvals.internal.customfield.ApprovalsCFValue#5e6792fb",
"customfield_10301": null,
"customfield_10302": null,
"customfield_10600": null,
"customfield_10700": null,
"customfield_11000": null,
"customfield_11001": null,
"customfield_11002": null,
"customfield_11003": null,
"customfield_11004": null,
"customfield_11005": null,
"customfield_11006": null,
"customfield_11007": null,
"customfield_11008": null,
"customfield_11009": null,
"customfield_11010": null,
"customfield_11011": null,
"customfield_11012": null,
"customfield_11013": null,
"customfield_11014": null,
"customfield_11015": null,
"customfield_11016": null,
"customfield_11017": null,
"customfield_11018": null,
"customfield_11019": null,
"customfield_11100": null,
"customfield_11101": null,
"customfield_11102": null,
"description": null,
"duedate": null,
"environment": null,
"fixVersions": [],
"issuelinks": [],
"issuetype": {
"avatarId": 10318,
"description": "A task that needs to be done.",
"iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"id": "10100",
"name": "Task",
"self": "https://jira.corp.company.com/rest/api/2/issuetype/10100",
"subtask": false
},
"labels": [],
"lastViewed": "2018-03-06T21:31:34.315+0000",
"priority": {
"iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
"id": "3",
"name": "Medium",
"self": "https://jira.corp.company.com/rest/api/2/priority/3"
},
"progress": {
"progress": 0,
"total": 0
},
"project": {
"avatarUrls": {
"16x16": "https://jira.corp.company.com/secure/projectavatar?size=xsmall&pid=10001&avatarId=10201",
"24x24": "https://jira.corp.company.com/secure/projectavatar?size=small&pid=10001&avatarId=10201",
"32x32": "https://jira.corp.company.com/secure/projectavatar?size=medium&pid=10001&avatarId=10201",
"48x48": "https://jira.corp.company.com/secure/projectavatar?pid=10001&avatarId=10201"
},
"id": "10001",
"key": "TECH",
"name": "Technology",
"self": "https://jira.corp.company.com/rest/api/2/project/10001"
},
"reporter": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user",
"emailAddress": "user#company.com",
"key": "user",
"name": "user",
"self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
"timeZone": "Europe/Belgrade"
},
"resolution": null,
"resolutiondate": null,
"status": {
"description": "",
"iconUrl": "https://jira.corp.company.com/",
"id": "10000",
"name": "Backlog",
"self": "https://jira.corp.company.com/rest/api/2/status/10000",
"statusCategory": {
"colorName": "blue-gray",
"id": 2,
"key": "new",
"name": "To Do",
"self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
}
},
"subtasks": [
{
"fields": {
"issuetype": {
"avatarId": 10316,
"description": "The sub-task of the issue",
"iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype",
"id": "10101",
"name": "Sub-task",
"self": "https://jira.corp.company.com/rest/api/2/issuetype/10101",
"subtask": true
},
"priority": {
"iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
"id": "3",
"name": "Medium",
"self": "https://jira.corp.company.com/rest/api/2/priority/3"
},
"status": {
"description": "",
"iconUrl": "https://jira.corp.company.com/",
"id": "10000",
"name": "Backlog",
"self": "https://jira.corp.company.com/rest/api/2/status/10000",
"statusCategory": {
"colorName": "blue-gray",
"id": 2,
"key": "new",
"name": "To Do",
"self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
}
},
"summary": "Disable user account in Local AD"
},
"id": "16916",
"key": "TECH-728",
"self": "https://jira.corp.company.com/rest/api/2/issue/16916"
}
],
"summary": "disable user mm",
"timeestimate": null,
"timeoriginalestimate": null,
"timespent": null,
"updated": "2018-03-06T21:27:22.000+0000",
"versions": [],
"votes": {
"hasVoted": false,
"self": "https://jira.corp.company.com/rest/api/2/issue/TECH-726/votes",
"votes": 0
},
"watches": {
"isWatching": true,
"self": "https://jira.corp.company.com/rest/api/2/issue/TECH-726/watchers",
"watchCount": 1
},
"workratio": -1
},
"id": "16914",
"key": "TECH-726",
"self": "https://jira.corp.company.com/rest/api/2/issue/16914"
}
],
"maxResults": 50,
"startAt": 0,
"total": 1
}
How to extract only part in subtasks section
(subtask:true) ?
tried with:
jq -r '.issues[] | .fields.issuetype.subtask' 1.json # and
jq -r '.subtasks[] |.fields.issuetype.subtask' 1.json
but always get false
jq -r '.subtasks[] | .fields.issuetype.subtask' 1.json
jq: error (at 1.json:231): Cannot iterate over null (null)

jq solution:
jq '.issues[].fields.subtasks[].fields | .issuetype.subtask, .summary' 1.json
The output:
true
"Disable user account in Local AD"

With respect to a best-practice mechanism to iterate over output in bash (assuming, here, that the subtask field will never contain a literal tab, and that summary will never contain a literal newline):
while IFS=$'\t' read -r subtask summary; do
echo "Got subtask $subtask and summary $summary"
done < <(jq -r '.issues[].fields.subtasks[].fields
| [.issuetype.subtask, .summary] | #tsv')
If you want to avoid those assumptions, you can do even better by using NUL delimiters, which will correctly handle all values which can potentially be stored in a variable in bash:
while IFS= read -r -d '' subtask && IFS= read -r -d '' summary; do
printf 'Got subtask %q and summary %q\n' "$subtask" "$summary"
done < <(jq -j '.issues[].fields.subtasks[].fields
| (.issuetype.subtask, "\u0000", .summary, "\u0000")')
Community Wiki since this answer is intended to address an issue observed in comments on the accepted answer, rather than addressing the original question as such.

Related

How to add key to json file using powershell

i have a json file like this:
[
{
"DisplayName": "Title1",
"SignInName": null,
"RoleDefinitionName": "Name1",
"RoleDefinitionId": "1111",
"ObjectId": "0111",
"ObjectType": "ServicePrincipal",
"CanDelegate": false,
"Description": null,
"ConditionVersion": null,
"Condition": null
},
{
"DisplayName": "Title2",
"SignInName": null,
"RoleDefinitionName": "Name2",
"RoleDefinitionId": "1111",
"ObjectId": "02222",
"ObjectType": "ServicePrincipal",
"CanDelegate": false,
"Description": null,
"ConditionVersion": null,
"Condition": null
},
{
"DisplayName": "Title3",
"SignInName": null,
"RoleDefinitionName": "Name3",
"RoleDefinitionId": "33333",
"ObjectId": "03333",
"ObjectType": "ServicePrincipal",
"CanDelegate": false,
"Description": null,
"ConditionVersion": null,
"Condition": null
}
]
I need to add a KEY at a start with all this json as a VALUE of that key using powershell script so it would look like this:
{
"ManagedIdentity": [
{
"DisplayName": "Title1",
"SignInName": null,
"RoleDefinitionName": "Name1",
"RoleDefinitionId": "1111",
"ObjectId": "0111",
"ObjectType": "ServicePrincipal",
"CanDelegate": false,
"Description": null,
"ConditionVersion": null,
"Condition": null
},
{
"DisplayName": "Title2",
"SignInName": null,
"RoleDefinitionName": "Name2",
"RoleDefinitionId": "1111",
"ObjectId": "02222",
"ObjectType": "ServicePrincipal",
"CanDelegate": false,
"Description": null,
"ConditionVersion": null,
"Condition": null
},
{
"DisplayName": "Title3",
"SignInName": null,
"RoleDefinitionName": "Name3",
"RoleDefinitionId": "33333",
"ObjectId": "03333",
"ObjectType": "ServicePrincipal",
"CanDelegate": false,
"Description": null,
"ConditionVersion": null,
"Condition": null
}
]
}
I should do it inside one script block, and i am not sure how to figure this out. It is a ready json file that i need to append key to.
The script that gets a file is something like this:
Get-AzRoleAssignment -ObjectId 02222 | ConvertTo-Json
to this short script using pipes i need to append a solution to append the key to the file.

Conditions In Jq tool

Greetings for the day!
how to get "created" value if "toString" value is Code Review from below json code.
Json code:-
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
"id": "562940",
"self": "https://example/rest/api/2/issue/562940",
"key": "TPR-13098",
"fields": {
"customfield_17384": null,
"customfield_17379": null,
"customfield_17378": null,
"labels": [
],
"customfield_15505": null,
"issuelinks": [
],
"customfield_11709": null,
"assignee": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"components": [
{
"self": "https://example/rest/api/2/component/17139",
"id": "17139",
"name": "Others"
}
],
"customfield_17366": null,
"customfield_11935": [
{
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
}
],
"customfield_11937": null,
"customfield_17351": "2021-06-30",
"subtasks": [
],
"customfield_17352": null,
"customfield_17359": null,
"reporter": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"customfield_17357": null,
"customfield_16700": null,
"customfield_11920": null,
"customfield_11922": null,
"progress": {
"progress": 0,
"total": 0
},
"worklog": {
"startAt": 0,
"maxResults": 20,
"total": 0,
"worklogs": [
]
},
"issuetype": {
"self": "https://example/rest/api/2/issuetype/12506",
"id": "12506",
"description": "",
"iconUrl": "https://example/secure/viewavatar?size=xsmall&avatarId=10306&avatarType=issuetype",
"name": "Work Item",
"subtask": false,
"avatarId": 10306
},
"customfield_17102": null,
"customfield_17347": null,
"project": {
"self": "https://example/rest/api/2/project/14309",
"id": "14309",
"key": "TPR",
"name": "TallyPrime",
"projectTypeKey": "software",
"avatarUrls": {
"48x48": "https://example/secure/projectavatar?avatarId=10703",
"24x24": "https://example/secure/projectavatar?size=small&avatarId=10703",
"16x16": "https://example/secure/projectavatar?size=xsmall&avatarId=10703",
"32x32": "https://example/secure/projectavatar?size=medium&avatarId=10703"
}
},
"customfield_17346": null,
"customfield_17103": null,
"customfield_17345": "-",
"customfield_15602": null,
"customfield_11486": null,
"customfield_15600": null,
"customfield_15601": null,
"customfield_16806": null,
"customfield_16804": null,
"customfield_11910": null,
"customfield_16803": null,
"customfield_11913": "2021-06-28",
"customfield_11912": null,
"customfield_11915": "2021-06-28",
"resolutiondate": null,
"customfield_11914": null,
"watches": {
"self": "https://example/rest/api/2/issue/TPR-13098/watchers",
"watchCount": 1,
"isWatching": false
},
"customfield_16002": null,
"customfield_17333": null,
"customfield_17331": 0.0,
"customfield_17330": null,
"customfield_16006": null,
"customfield_16005": null,
"customfield_16003": null,
"customfield_16802": null,
"customfield_16009": null,
"customfield_16801": null,
"customfield_16800": null,
"customfield_17339": null,
"customfield_16007": null,
"customfield_17338": null,
"updated": "2021-06-29T17:40:13.000+0530",
"customfield_17322": null,
"customfield_17321": null,
"timeoriginalestimate": null,
"customfield_17326": null,
"description": "Clean up of JsonElem::GetOwnName as it is duplicate of JsonElem::GetKey.",
"customfield_10010": "0|i2he8j:",
"customfield_17323": null,
"customfield_11344": 0.0,
"customfield_17329": null,
"timetracking": {
},
"customfield_15700": {
"self": "https://example/rest/api/2/customFieldOption/16104",
"value": "Thank you",
"id": "16104"
},
"customfield_10005": null,
"customfield_14726": null,
"customfield_10006": null,
"customfield_14724": null,
"customfield_14725": null,
"summary": "Clean up of GetOwnName from JsonElem class",
"customfield_16101": null,
"customfield_17311": null,
"customfield_16100": null,
"customfield_17310": null,
"customfield_16103": null,
"customfield_16102": null,
"customfield_17312": null,
"customfield_14722": null,
"customfield_14723": null,
"customfield_17318": null,
"customfield_14721": null,
"customfield_11204": null,
"customfield_11205": "0.0",
"environment": null,
"customfield_11206": 0.0,
"customfield_10118": null,
"duedate": null,
"comment": {
"comments": [
],
"maxResults": 0,
"total": 0,
"startAt": 0
},
"customfield_17300": null,
"customfield_17304": "3.Coding",
"customfield_17303": null,
"fixVersions": [
{
"self": "https://example/rest/api/2/version/18013",
"id": "18013",
"description": "This is for Release B1 of GST Revamp planned as part of TallyPrime",
"name": "TallyPrime Release 3.0",
"archived": false,
"released": false
}
],
"customfield_17301": {
"self": "https://example/rest/api/2/customFieldOption/18133",
"value": "Client",
"id": "18133"
},
"customfield_15800": null,
"customfield_17307": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"customfield_17305": null,
"customfield_14704": null,
"customfield_14705": null,
"timeestimate": null,
"status": {
"self": "https://example/rest/api/2/status/12606",
"description": "",
"iconUrl": "https://example/images/icons/statuses/generic.png",
"name": "Code Review",
"id": "12606",
"statusCategory": {
"self": "https://example/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"customfield_17403": null,
"customfield_17401": null,
"customfield_15102": {
"self": "https://example/rest/api/2/customFieldOption/18132",
"value": "Code Improvement",
"id": "18132"
},
"customfield_17400": null,
"customfield_15900": null,
"customfield_17406": null,
"customfield_17405": null,
"customfield_17404": null,
"customfield_14802": null,
"aggregatetimeestimate": null,
"creator": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"aggregateprogress": {
"progress": 0,
"total": 0
},
"timespent": null,
"customfield_15202": [
],
"customfield_15203": null,
"customfield_15200": null,
"customfield_15201": null,
"aggregatetimespent": null,
"customfield_15204": null,
"workratio": -1,
"customfield_15306": null,
"customfield_15303": null,
"attachment": [
],
"customfield_10527": null,
"customfield_10518": null
},
"changelog": {
"startAt": 0,
"maxResults": 4,
"total": 4,
"histories": [
{
"id": "3818773",
"author": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-28T16:34:02.000+0530",
"items": [
{
"field": "status",
"fieldtype": "jira",
"from": "10114",
"fromString": "New",
"to": "12605",
"toString": "Coding"
}
]
},
{
"id": "3818870",
"author": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-28T17:23:44.000+0530",
"items": [
{
"field": "status",
"fieldtype": "jira",
"from": "12605",
"fromString": "Coding",
"to": "12606",
"toString": "Code Review"
}
]
},
{
"id": "3820419",
"author": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-29T17:40:12.000+0530",
"items": [
{
"field": "Coding Due Date",
"fieldtype": "custom",
"from": null,
"fromString": null,
"to": "2021-06-30",
"toString": "30/Jun/21"
}
]
},
{
"id": "3820420",
"author": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-29T17:40:13.000+0530",
"items": [
{
"field": "assignee",
"fieldtype": "jira",
"from": "testuser",
"fromString": "testuser",
"to": "example",
"toString": "example"
}
]
}
]
}
}
..
| objects
| select(has("created") and any(.items[]; .toString == "Code Review"))
| .created
Research Effort
For future reference, please note that, since you've been a member of the SO community for over a year and have asked other questions, you should be familiar with the SO guidelines for asking appropriate questions. Apart from the "miminum reproducible example" guidelines already mentioned on this page, there should be some evidence of "research effort" as per
How much research effort is expected of Stack Overflow users?

Firebase: JSON payload not accepted

I'm trying to push JSON from a service in to Firebase, and it's not accepting it.
I cant figure out why. JSONLint validates it as valid.
The error I get is:
error: "Invalid data; couldn't parse JSON object, array, or value."
Here's the JSON payload:
{
"app_id": "e4805b8d5a9f4032b0bb8b6d9c6726b8",
"archived": false,
"attachments": {
"form.xml": {
"content_type": "text/xml",
"length": 4500,
"url": "https://someurl.com/form.xml"
}
},
"build_id": "3c5703e20346462ebcb07a3f36d5fe9b",
"domain": "my-test",
"edited_by_user_id": null,
"edited_on": null,
"form": {
"#type": "data",
"#name": "Beneficiary Registration",
"#uiVersion": "1",
"#version": "1",
"#xmlns": "http://openrosa.org/formdesigner/123456",
"beneficiary_age": {
"beneficiary_age_num": "8",
"beneficiary_exact_age_ind": "N"
},
"beneficiary_gender_cd": "M",
"beneficiary_id": "Hhr-O6I3C5L-J3G1L",
"case": {
"#case_id": "a07972bc-1a34-4c84-90ea-91250639f2a4",
"#date_modified": "2020-03-17T20:57:26.986000Z",
"#user_id": "2275c340c48ac83b6852035b0a15b5d3",
"#xmlns": "http://someurl.org/case/transaction/v2"
},
"case_name": "Hhr-O6I3C5L-J3G1L|joel galager|Katsekera|Katsekera|Mpando|Katsekera|KE",
"existing_beneficiaries": "Jane Doe\n\nJoan Doe",
"existing_beneficiaries_label": "",
"household_information": {
"beneficiary_household_information_display": "",
"beneficiary_location_hierarchy_1": "KE",
"beneficiary_location_hierarchy_1_text": "Kenya",
"beneficiary_location_hierarchy_2": "HF0001",
"beneficiary_location_hierarchy_2_text": "Katsekera",
"beneficiary_location_hierarchy_3": "TA0001",
"beneficiary_location_hierarchy_3_text": "Mpando",
"beneficiary_location_hierarchy_4": "GHV0001",
"beneficiary_location_hierarchy_4_text": "Katsekera",
"beneficiary_location_hierarchy_5": "V0001",
"beneficiary_location_hierarchy_5_text": "Katsekera",
"correct_information": "",
"hh_first_name": "John",
"hh_full_name": "John Doe",
"hh_id_fk": "Hhr-O6I3C5L",
"hh_last_name": "Doe",
"household_information": ""
},
"meta": {
"#xmlns": "http://openrosa.org/jr/xforms",
"appVersion": "Formplayer Version: 2.47",
"app_build_version": 1,
"commcare_version": null,
"deviceID": "Formplayer",
"drift": "0",
"geo_point": null,
"instanceID": "123-321-232",
"timeEnd": "2020-03-17T20:57:26.986000Z",
"timeStart": "2020-03-17T20:57:13.958000Z",
"userID": "2275c340c48ac83b6852035b0a15b5d3",
"username": "some_username"
},
"name_group": {
"beneficiary_first_name": "joel",
"beneficiary_full_name": "joel galager",
"beneficiary_last_name": "galager"
},
"subcase_0": {
"case": {
"#case_id": "2a4bfe27-a5c3-4f3a-8540-5f8ded86db85",
"#date_modified": "2020-03-17T20:57:26.986000Z",
"#user_id": "abc123",
"#xmlns": "http://commcarehq.org/case/transaction/v2",
"create": {
"case_name": "Hhr-O6I3C5L-J3G1L|joel galager|Katsekera|Katsekera|Mpando|Katsekera|KE",
"case_type": "beneficiary_case",
"owner_id": "abc123"
},
"index": {
"parent": {
"#text": "a07972bc-1a34-4c84-90ea-91250639f2a4",
"#case_type": "household_case"
}
},
"update": {
"beneficiary_age_num": "8",
"beneficiary_exact_age_ind": "N",
"beneficiary_first_name": "joel",
"beneficiary_full_name": "joel galager",
"beneficiary_gender_cd": "M",
"beneficiary_id": "Hhr-O6I3C5L-J3G1L",
"beneficiary_last_name": "galager",
"beneficiary_location_hierarchy_1": "KE",
"beneficiary_location_hierarchy_1_text": "Kenya",
"beneficiary_location_hierarchy_2": "HF0001",
"beneficiary_location_hierarchy_2_text": "Katsekera",
"beneficiary_location_hierarchy_3": "TA0001",
"beneficiary_location_hierarchy_3_text": "Mpando",
"beneficiary_location_hierarchy_4": "GHV0001",
"beneficiary_location_hierarchy_4_text": "Katsekera",
"beneficiary_location_hierarchy_5": "V0001",
"beneficiary_location_hierarchy_5_text": "Katsekera",
"hh_id_fk": "Hhr-O6I3C5L"
}
}
}
},
"id": "d547ccea-503c-4c50-b974-38ed564ae78a",
"indexed_on": "2020-03-17T21:01:04.695654",
"initial_processing_complete": true,
"is_phone_submission": true,
"metadata": {
"appVersion": "Formplayer Version: 2.47",
"app_build_version": 1,
"commcare_version": null,
"deviceID": "Formplayer",
"drift": "0",
"geo_point": null,
"instanceID": "01010101",
"location": null,
"timeEnd": "2020-03-17T20:57:26.986000Z",
"timeStart": "2020-03-17T20:57:13.958000Z",
"userID": "2275c340c48ac83b6852035b0a15b5d3",
"username": "myusername"
},
"problem": null,
"received_on": "2020-03-17T20:57:27.179986Z",
"resource_uri": "",
"server_modified_on": "2020-03-17T20:57:27.382548Z",
"type": "data",
"uiversion": "1",
"version": "1"
}
This is probably because of #type inside form.
The # character can't be used in RTDB paths.
See How data is structured from the docs.
Keys cannot contain
.
$
#
[
]
/
ASCII control characters 0-31 or 127

Searching JSON file using bash

i have JSON file and want to extract only some values
How to extract only "key": "TECH-456",
and "key": "TECH", (values after key)
{
"expand": "names,schema",
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"fields": {
"aggregateprogress": {
"percent": 100,
"progress": 86400,
"total": 86400
},
"aggregatetimeestimate": 0,
"aggregatetimeoriginalestimate": 57600,
"aggregatetimespent": 86400,
"assignee": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user1",
"emailAddress": "user1#gmail.com",
"key": "user1",
"name": "user1",
"self": "https://mycompany/rest/api/2/user?username=user1",
"timeZone": "Europe/Belgrade"
},
"components": [],
"created": "2018-01-10T10:23:01.000+0000",
"creator": {
"active": true,
"avatarUrls": {
"16x16": "https://mycompany/secure/useravatar?size=xsmall&avatarId=10349",
"24x24": "https://mycompany/secure/useravatar?size=small&avatarId=10349",
"32x32": "https://mycompany/secure/useravatar?size=medium&avatarId=10349",
"48x48": "https://mycompany/secure/useravatar?avatarId=10349"
},
"displayName": "user2",
"emailAddress": "user2#gmail.com",
"key": "user2",
"name": "user2",
"self": "https://mycompany/rest/api/2/user?username=user2",
"timeZone": "Zulu"
},
"customfield_10000": null,
"customfield_10001": null,
"customfield_10002": null,
"customfield_10004": "0|i00n0f:",
"customfield_10005": null,
"customfield_10006": null,
"customfield_10100": null,
"customfield_10101": [],
"customfield_10102": null,
"customfield_10103": null,
"customfield_10107": {
"id": "10400",
"self": "https://mycompany/rest/api/2/customFieldOption/10400",
"value": "Hentsu Internal"
},
"customfield_10108": null,
"customfield_10200": null,
"customfield_10201": "2018-01-12",
"customfield_10202": "2018-01-12",
"customfield_10203": null,
"customfield_10204": null,
"customfield_10205": null,
"customfield_10206": null,
"customfield_10300": "com.atlassian.servicedesk.plugins.approvals.internal.customfield.ApprovalsCFValue#40efdb56",
"customfield_10301": null,
"customfield_10302": null,
"customfield_10600": null,
"customfield_10700": null,
"customfield_11000": null,
"customfield_11001": null,
"customfield_11002": null,
"customfield_11003": null,
"customfield_11004": null,
"customfield_11005": null,
"customfield_11006": null,
"customfield_11007": null,
"customfield_11008": null,
"customfield_11009": null,
"customfield_11010": null,
"customfield_11011": null,
"customfield_11012": null,
"customfield_11013": null,
"customfield_11014": null,
"customfield_11015": null,
"customfield_11016": null,
"customfield_11017": null,
"customfield_11018": null,
"customfield_11019": null,
"customfield_11100": null,
"customfield_11101": null,
"customfield_11102": null,
"description": ".",
"duedate": null,
"environment": null,
"fixVersions": [],
"issuelinks": [],
"issuetype": {
"avatarId": 10318,
"description": "A task that needs to be done.",
"iconUrl": "https://mycompany/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"id": "10100",
"name": "Task",
"self": "https://mycompany/rest/api/2/issuetype/10100",
"subtask": false
},
"labels": [],
"lastViewed": "2018-02-22T15:47:47.792+0000",
"priority": {
"iconUrl": "https://mycompany/images/icons/priorities/medium.svg",
"id": "3",
"name": "Medium",
"self": "https://mycompany/rest/api/2/priority/3"
},
"progress": {
"percent": 100,
"progress": 86400,
"total": 86400
},
"project": {
"avatarUrls": {
"16x16": "https://mycompany/secure/projectavatar?size=xsmall&pid=10001&avatarId=10201",
"24x24": "https://mycompany/secure/projectavatar?size=small&pid=10001&avatarId=10201",
"32x32": "https://mycompany/secure/projectavatar?size=medium&pid=10001&avatarId=10201",
"48x48": "https://mycompany/secure/projectavatar?pid=10001&avatarId=10201"
},
"id": "10001",
"key": "TECH",
"name": "Technology",
"self": "https://mycompany/rest/api/2/project/10001"
},
"reporter": {
"active": true,
"avatarUrls": {
"16x16": "https://mycompany/secure/useravatar?size=xsmall&avatarId=10349",
"24x24": "https://mycompany/secure/useravatar?size=small&avatarId=10349",
"32x32": "https://mycompany/secure/useravatar?size=medium&avatarId=10349",
"48x48": "https://mycompany/secure/useravatar?avatarId=10349"
},
"displayName": "user2",
"emailAddress": "user2#gmail.com",
"key": "user2",
"name": "user2",
"self": "https://mycompany/rest/api/2/user?username=user2",
"timeZone": "Zulu"
},
"resolution": null,
"resolutiondate": null,
"status": {
"description": "",
"iconUrl": "https://mycompany/images/icons/statuses/inprogress.png",
"id": "3",
"name": "In-Progress",
"self": "https://mycompany/rest/api/2/status/3",
"statusCategory": {
"colorName": "yellow",
"id": 4,
"key": "indeterminate",
"name": "In Progress",
"self": "https://mycompany/rest/api/2/statuscategory/4"
}
},
"subtasks": [],
"summary": "Build the Fortimanage Portal",
"timeestimate": 0,
"timeoriginalestimate": 57600,
"timespent": 86400,
"updated": "2018-01-31T15:22:06.000+0000",
"versions": [],
"votes": {
"hasVoted": false,
"self": "https://mycompany/rest/api/2/issue/TECH-456/votes",
"votes": 0
},
"watches": {
"isWatching": false,
"self": "https://mycompany/rest/api/2/issue/TECH-456/watchers",
"watchCount": 1
},
"workratio": 150
},
"id": "15377",
"key": "TECH-456",
"self": "https://mycompany/rest/api/2/issue/15377"
}
],
"maxResults": 50,
"startAt": 0,
"total": 1
}
The right way with jq tool:
jq -r '.issues[0] | .key, .fields.project.key' file.json
The output:
TECH-456
TECH

How to loop through JSON in ruby

Below details is my shipment details. I want to loop through this JSON and get each checkpoint details.
How can I do this with Ruby
This is my controller:
#asd = AfterShip::V4::Tracking.get('ups', '1Z31Y1Y90490064644')
this is my view page where i get json data
= #asd.to_json`
This is the JSON:
{
"meta": {
"code": 200
},
"data": {
"tracking": {
"id": "560b87b38c9079f272e98dfc",
"created_at": "2015-09-30T06:56:51+00:00",
"updated_at": "2015-09-30T06:56:55+00:00",
"last_updated_at": "2015-09-30T06:56:55+00:00",
"tracking_number": "1Z31Y1Y90490064644",
"slug": "ups",
"active": false,
"android": [
],
"custom_fields": null,
"customer_name": null,
"delivery_time": 7,
"destination_country_iso3": "GBR",
"emails": [
"pu#l.com"
],
"expected_delivery": null,
"ios": [
],
"note": null,
"order_id": null,
"order_id_path": null,
"origin_country_iso3": "HKG",
"shipment_package_count": 1,
"shipment_pickup_date": "2015-08-24T16:00:00",
"shipment_delivery_date": "2015-09-01T14:22:00",
"shipment_type": "UPS SAVER",
"shipment_weight": 0.5,
"shipment_weight_unit": "kg",
"signed_by": "MANTON (RESIDENTIAL)",
"smses": [
],
"source": "api",
"tag": "Delivered",
"title": "1Z31Y1Y90490064644",
"tracked_count": 1,
"unique_token": "bkGcaTOJDe",
"checkpoints": [
{
"slug": "ups",
"city": null,
"created_at": "2015-09-30T06:56:55+00:00",
"location": "HK",
"country_name": "HK",
"message": "BILLING INFORMATION RECEIVED",
"country_iso3": "HKG",
"tag": "InfoReceived",
"checkpoint_time": "2015-08-25T23:05:47",
"coordinates": [
],
"state": null,
"zip": null
},
{
"slug": "ups",
"city": null,
"created_at": "2015-09-30T06:56:55+00:00",
"location": null,
"country_name": null,
"message": "YOUR PACKAGE WAS RELEASED BY THE CLEARING AGENCY.",
"country_iso3": null,
"tag": "InTransit",
"checkpoint_time": "2015-08-27T16:57:00",
"coordinates": [
],
"state": null,
"zip": null
},
{
"slug": "ups",
"city": null,
"created_at": "2015-09-30T06:56:55+00:00",
"location": null,
"country_name": null,
"message": "YOUR PACKAGE WAS RELEASED BY THE CLEARING AGENCY.",
"country_iso3": null,
"tag": "InTransit",
"checkpoint_time": "2015-08-27T17:07:00",
"coordinates": [
],
"state": null,
"zip": null
}
}
}
}
What you are getting here is an instance of Hash class (the response JSON is already parsed).
tracking = AfterShip::V4::Tracking.get('ups', '1Z31Y1Y90490064644')
tracking['data']['tracking']['id']
# => "560b87b38c9079f272e98dfc"