jq - Argument list too long error bash.md

February 2, 2020 ยท View on GitHub

Query: /usr/bin/jq: Argument list too long error bash

(jump to the answer)

I want to replace the value in sample json from larger swagger.json file content and it is too large.

Error:
/usr/bin/jq: Argument list too long error bash 

worked to solve this issue for a few days and cannot identify the issue here. this is the sample json file:

{
   "name": "",
   "description": "",
   "context": "",
   "version": "",
   "provider": "cbs",
   "apiDefinition": "",
   "wsdlUri": null,
   "responseCaching": "Disabled",
   "cacheTimeout": 300,
   "destinationStatsEnabled": false,
   "isDefaultVersion": true,
   "transport":    [
      "http",
      "https"
   ],
   "tags": ["PROVIDER_","MIFE"],
   "tiers": ["Unlimited","Default","Silver","Subscription","Gold","Premium","Bronze"],
   "maxTps":    {
      "sandbox": 5000,
      "production": 1000
   },
   "visibility": "PUBLIC",
   "visibleRoles": [],
   "endpointConfig": "",
   "endpointSecurity":    {
      "username": "user",
      "type": "basic",
      "password": "pass"
   },
   "gatewayEnvironments": "Production and Sandbox",
   "sequences": [],
   "subscriptionAvailability": null,
   "subscriptionAvailableTenants": [],
   "businessInformation":    {
      "businessOwnerEmail": "BUSINESSOWNEREMAIL_",
      "technicalOwnerEmail": "TECHNICALOWNEREMAIL_",
      "technicalOwner": "TECHNICALOWNER_",
      "businessOwner": "BUSINESSOWNER_"
   },
   "corsConfiguration":    {
      "accessControlAllowOrigins": ["*"],
      "accessControlAllowHeaders":       [
         "authorization",
         "Access-Control-Allow-Origin",
         "Content-Type",
         "SOAPAction"
      ],
      "accessControlAllowMethods":       [
         "GET",
         "PUT",
         "POST",
         "DELETE",
         "PATCH",
         "OPTIONS"
      ],
      "accessControlAllowCredentials": false,
      "corsConfigurationEnabled": false
   }
}

this is the command i using and it give me a error which i as arguments too large.

swagger = $(cat swagger.json)

jq -r --arg swagger "$swagger" '.apiDefinition = $swagger' <<<"$json"

Can anyone please help!

swagger = $(cat swagger.json)

A:

the request here: insert a rather a very large JSON into a specific location of a sample JSON. With jtc there's no issue, as it handles any size JSON of argument (as long memory permits):

bash $ <sample.json jtc -w'<apiDefinition>l' -u swagger.json 
...

Of course, if in-place update is required into the source file use -f option:

bash $ jtc -w'<apiDefinition>l' -u swagger.json -f sample.json