I have over 500 JSON files where I have to change a value of a lang key from en to de
This is how the structure of the files looks like
{
"id": "a7b9e1b4-3d91-4e1b-946a-8c4b92b78d31",
"name": "smart.emoji.gb.country",
"auto": true,
"contexts": [],
"responses": [
{
"resetContexts": false,
"affectedContexts": [],
"parameters": [],
"messages": [
{
"type": 0,
"lang": "en",
"speech": "Country Flag"
}
],
"defaultResponsePlatforms": {},
"speech": []
}
],
"priority": 500000,
"webhookUsed": false,
"webhookForSlotFilling": false,
"lastUpdate": 1525736163,
"fallbackIntent": false,
"events": []
}
All the files are in the same folder.
Any idea how can I do it automatically?
I found an answer - Notepad++ has this functionality.
Related
I just want to be able to go through the individual gs files as blobs to summarize some information about the entire project. I think I CAN do this with drive api but I need to know the individual files first.
Solution:
Yes, you can do this with Drive API:
First you need to use DriveApp.getFilesByType("application/vnd.google-apps.script") to get the list of Apps Script projects in your Drive.
Sample List:
{
"kind": "drive#fileList",
"etag": "\"kjsas92/f3zGUXczKMxEB_9ZTMRFOF3d1ZU\"",
"selfLink": "https://www.googleapis.com/drive/v2/files?q=mimeType%3D'application/vnd.google-apps.script'+and+'me'+in+owners",
"items": [
{
"kind": "drive#file",
"id": "1vi0uwcMdHsRv1YFtgq7XdiTGSdqgjIYpdQNC0A_Udn79LOhH0vYL132D",
"etag": "\"kjsas92/MTM3MDk3ODY5ODQyNg\"",
"selfLink": "https://www.googleapis.com/drive/v2/files/1vi0uwcMdHsRv1YFtgq7XdiTGSdqgjIYpdQNC0A_Udn79LOhH0vYL132D",
"alternateLink": "https://script.google.com/a/google.com/d/1vi0uwcMdHsRv1YFtgq7XdiTGSdqgjIYpdQNC0A_Udn79LOhH0vYL132D/edit?usp=drivesdk",
"iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_11_script_list.png",
"title": "Mail merge",
"mimeType": "application/vnd.google-apps.script",
"description": "",
"labels": {
"starred": false,
"hidden": false,
"trashed": true,
"restricted": false,
"viewed": true
},
"createdDate": "2013-06-11T19:24:45.188Z",
"modifiedDate": "2013-06-11T19:24:58.426Z",
"modifiedByMeDate": "2013-06-11T19:24:58.426Z",
"lastViewedByMeDate": "2013-06-11T19:24:58.426Z",
"parents": [
{
"kind": "drive#parentReference",
"id": "0APdyIOzo7bWDUk9PVA",
"selfLink": "https://www.googleapis.com/drive/v2/files/1vi0uwcMdHsRv1YFtgq7XdiTGSdqgjIYpdQNC0A_Udn79LOhH0vYL132D/parents/0APdyIOzo7bWDUk9PVA",
"parentLink": "https://www.googleapis.com/drive/v2/files/0APdyIOzo7bWDUk9PVA",
"isRoot": true
}
],
"exportLinks": {
"application/json": "https://script.google.com/feeds/download/export?id=1234567890abcefghijklmnopqrstuvwxyz&format=json"
},
"userPermission": {
"kind": "drive#permission",
"etag": "\"kjsas92/259X2r5DVstv1CcIQTjt_RQPSW8\"",
"id": "me",
"selfLink": "https://www.googleapis.com/drive/v2/files/1vi0uwcMdHsRv1YFtgq7XdiTGSdqgjIYpdQNC0A_Udn79LOhH0vYL132D/permissions/me",
"role": "owner",
"type": "user"
},
"quotaBytesUsed": "0",
"ownerNames": [
"John Doe"
],
"owners": [
{
"kind": "drive#user",
"displayName": "John Doe",
"picture": {
"url": "https://lh4.googleusercontent.com/-yd1rIb6Pe2Y/AAAAAAAAAAI/AAAAAAAAAGs/PP5vTuZonik/s64/photo.jpg"
},
"isAuthenticatedUser": true,
"permissionId": "1234566789"
}
],
"lastModifyingUserName": "John Doe",
"lastModifyingUser": {
"kind": "drive#user",
"displayName": "John Doe",
"picture": {
"url": "https://lh4.googleusercontent.com/-yd1rIb6Pe2Y/AAAAAAAAAAI/AAAAAAAAAGs/PP5vTuZonik/s64/photo.jpg"
},
"isAuthenticatedUser": true,
"permissionId": "1234566789"
},
"editable": true,
"writersCanShare": true,
"shared": false,
"explicitlyTrashed": true,
"appDataContents": false
}
]
}
Then each individual project has exportLinks property that has a link to the scripts inside. You need to fetch that URL to get a JSON response that has the individual files and script ID's.
Sample JSON:
{
"files": [
{
"id":"9basdfbd-749a-4as9b-b9d1-d64basdf803",
"name":"Code",
"type":"server_js",
"source":"function doGet() {\n return HtmlService.createHtmlOutputFromFile(\u0027index\u0027);\n}\n"
},
{
"id":"3asf7c0d-1afb-4a9-8431-5asdfc79e7ae",
"name":"index",
"type":"html",
"source":"\u003chtml\u003e\n \u003cbody\u003e\n Hello, world!\n \u003c/body\u003e\n\u003c/html\u003e"
}
]
}
References:
Import and Export Projects
Get Files by Type
Files Resource
I am trying to modify a large json file (a Grafana dashboard), replacing a single value, then output the whole file with the change. How can I do this?
You can see the value I want to edit here. The actual file is quite large, so there are many other top-level values, but I only need to edit a specific item under the "templating" block.
"templating": {
"list": [
{
"allValue": ".*",
"current": {},
"datasource": "$Source",
"hide": 0,
"includeAll": false,
"label": null,
"multi": true,
"name": "node",
"options": [],
"query": "label_values(node_boot_time{env=~\"$env\"}, instance)",
"refresh": 1,
"regex": "",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": null,
"current": {
"tags": [],
"text": "",
"value": ""
},
"datasource": "$Source",
"definition": "label_values(env)",
"hide": 0,
"includeAll": true,
"label": "env",
"multi": false,
"name": "env",
"options": [],
"query": "label_values(env)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 1,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"current": {
"tags": [],
"text": "",
"value": ""
},
"hide": 0,
"includeAll": false,
"label": null,
"multi": false,
"name": "Source",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"type": "datasource"
}
]
},
The piece I need to change is the block containing "query": "label_values(env)", and I just need to change the value of "regex": "",
I have tried:
jq '.templating.list[] | select(.name == "env") |= . + {regex:"*"}' "dashboard.json" > test.json
The problem is then it only prints the ".list[]" elements instead of the whole file. I need to be able to make this change for multiple other files that will have the same block, but not necessarily in the same place so I can't just select by index number.
Output of above script:
{
"allValue": ".*",
"current": {},
"datasource": "$Source",
"hide": 0,
"includeAll": false,
"label": null,
"multi": true,
"name": "node",
"options": [],
"query": "label_values(node_boot_time{env=~\"$env\"}, instance)",
"refresh": 1,
"regex": "",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
{
"allValue": null,
"current": {
"tags": [],
"text": "",
"value": ""
},
"datasource": "$Source",
"definition": "label_values(env)",
"hide": 0,
"includeAll": true,
"label": "env",
"multi": false,
"name": "env",
"options": [],
"query": "label_values(env)",
"refresh": 1,
"regex": "*",
"skipUrlSync": false,
"sort": 1,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
{
"current": {
"tags": [],
"text": "",
"value": ""
},
"hide": 0,
"includeAll": false,
"label": null,
"multi": false,
"name": "Source",
"options": [],
"query": "prometheus",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"type": "datasource"
}
Position |= earlier to retain the original structure.
.templating.list[] |= (select(.name == "env") .regex = "*")
Online demo
Your expected output isn't quite matching with your description of your problem. If your requirement is to find inside templating list find the query containing "label_values(env)" and update the regex to "" you need below. To change it to *, use regex = "*"
.templating.list[] |= ( select(.query == "label_values(env)").regex = "")
The key is to use the right path and use the select operator to get the object to update using the |= operator
jq-play snippet
I have a JSON data and able to get the JSON data into a string.
I wish to get a json array from the root object one by one (using a loop if many are there)
The returned object must be of type "com.google.gson.JsonObject" as another method takes this object as input to get me the attribute values.
my json looks like this:
I would be needing the json array in "Resources" -
{
"totalResults": 2,
"startIndex": 1,
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:ListResponse"
],
"Resources": [
{
"owner": {},
"application": {
"displayName": "Non Auth App",
"value": "4028b88168fa3d38016900d1759405a6",
"$ref": "http://localhost:8080/identityiq/scim/v2/Applications/4028b88168fa3d38016900d1759405a6"
},
"meta": {
"created": "2019-03-22T18:40:30.505+05:30",
"location": "http://localhost:8080/identityiq/scim/v2/Entitlements/297eff8a699f8b3a0169a5863769008b",
"version": "W/\"1553260230505\"",
"resourceType": "Entitlement"
},
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:Entitlement"
],
"displayableName": "reader",
"aggregated": false,
"id": "297eff8a699f8b3a0169a5863769008b",
"requestable": true,
"attribute": "Privileges",
"type": "Entitlement",
"descriptions": [],
"value": "reader"
},
{
"owner": {},
"application": {
"displayName": "Non Auth App",
"value": "4028b88168fa3d38016900d1759405a6",
"$ref": "http://localhost:8080/identityiq/scim/v2/Applications/4028b88168fa3d38016900d1759405a6"
},
"meta": {
"created": "2019-03-18T19:11:47.912+05:30",
"location": "http://localhost:8080/identityiq/scim/v2/Entitlements/297eff8a6990fc49016991096d08001e",
"version": "W/\"1552916507912\"",
"resourceType": "Entitlement"
},
"schemas": [
"urn:ietf:params:scim:schemas:sailpoint:1.0:Entitlement"
],
"displayableName": "admin",
"aggregated": false,
"id": "297eff8a6990fc49016991096d08001e",
"requestable": true,
"attribute": "Privileges",
"type": "Entitlement",
"descriptions": [],
"value": "admin"
}
]
}
Any help is appreciated.
I have a JSON of the below format
{
"board_title": "test",
"read_only": false,
"isIntegration": false,
"board_bgtype": "board_graph",
"created": "2017-08-16T06:40:47.158868+00:00",
"original_title": "Revised_CID_Templating-test(cloned)",
"modified": "2017-08-31T11:52:22.115661+00:00",
"disableEditing": false,
"height": 111,
"width": "100%",
"template_variables": [
{
"default": "identity",
"prefix": "v1",
"name": "env"
}
],
"created_by": {
"disabled": false,
"handle": "xx.com",
"name": null,
"is_admin": false,
"role": null,
"access_role": "st",
"verified": true,
"email": "xx.com",
"icon": "https://secure.gravatar.com/avatar/86fd6c17deba27cfc4081134a5bc0c6a?s=48&d=retro"
},
...
}
I need to load this JSON using Python and edit the value of
"template_variables": [
{
"default": "identity"
To some other value, say:
default : "com"
I load it using Python script and traverse and print the key value pair but not able to understand how to modify it.
How can I assign a value to the first child of template variables and save the JSON in the same file and post it using request?
You can think of json object as a dictionary.
try this.
import json
jsonData = '''{
"board_title": "test",
"read_only": false,
"isIntegration": false,
"board_bgtype": "board_graph",
"created": "2017-08-16T06:40:47.158868+00:00",
"original_title": "Revised_CID_Templating-test(cloned)",
"modified": "2017-08-31T11:52:22.115661+00:00",
"disableEditing": false,
"height": 111,
"width": "100%",
"template_variables": [
{
"default": "identity",
"prefix": "v1",
"name": "env"
}
],
"created_by": {
"disabled": false,
"handle": "xx.com",
"name": null,
"is_admin": false,
"role": null,
"access_role": "st",
"verified": true,
"email": "xx.com",
"icon": "https://secure.gravatar.com/avatar/86fd6c17deba27cfc4081134a5bc0c6a?s=48&d=retro"
}
}'''
jsonToPython = json.loads(jsonData)
print (jsonToPython['template_variables'][0]['default'])
jsonToPython['template_variables'][0]['default'] = 'test'
print (jsonToPython['template_variables'][0]['default'])
as you can see jsonToPython is being modified.
I try to change the storage configuration in apache drill in embedded mode to identify headers and to change the delimiter of csv files. I also renamed the new format category from csv to sap.
I tried to use the information from the documentation and created the following json storage information:
{
"type": "file",
"enabled": true,
"connection": "file:///",
"workspaces": {
"root": {
"location": "/",
"writable": false,
"defaultInputFormat": null
},
"tmp": {
"location": "/tmp",
"writable": true,
"defaultInputFormat": null
}
},
"formats": {
"sap": {
"type": "text",
"extensions": [
"sap"
],
"skipFirstLine": false,
"extractHeader": true,
"delimiter": "|"
},
"psv": {
"type": "text",
"extensions": [
"tbl"
],
"delimiter": "|"
},
"csv": {
"type": "text",
"extensions": [
"csv"
],
"delimiter": ","
},
"tsv": {
"type": "text",
"extensions": [
"tsv"
],
"delimiter": "\t"
},
"parquet": {
"type": "parquet"
},
"json": {
"type": "json"
},
"avro": {
"type": "avro"
}
}
}
But always when I try to save it in the web-ui I got the message: error (invalid json mapping).
The exec.storage.enable_new_text_reader is set true.
Could somebody help my how I can add the two config items: skipFirstLine and extractHeader?
BR
Drill is able to parse the header row in a text file (CSV, TSV, etc.) in Drill 1.3. Check documentation for this.
Check Release notes for Dill 1.3 and csv header parsing issue for more details.