Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

jq

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
   }
}
  • swagger.json file - Click here to download swagger.json file

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)

like image 282
harsha rachith Avatar asked Mar 02 '23 21:03

harsha rachith


1 Answers

The Q does not explicitly say how $swagger has been set, but it would seem that rather than using --arg swagger $swagger you would be better off using one of the file-oriented command-line options, perhaps along the lines of:

--argfile swagger swagger.json

There are many alternatives, but to explore these sensibly here, it would be best if you provided at least one complete but very TINY example. (The example does NOT have to illustrate the "Argument list too long" error!)

Caveat

If you are worried that the --argfile option is deprecated, then by all means use --slurpfile instead if your jq has it, but note that the latter option wraps the file contents into a JSON array, so you would have to take that into account.

These and other options are all presented succinctly in the official documentation at https://stedolan.github.io/jq/manual/

like image 143
peak Avatar answered Mar 05 '23 19:03

peak