json parse extract substringSplit a string by spaces — preserving quoted substrings — in PythonHow can I extract a predetermined range of lines from a text file on Unix?Regular expression to extract text between square bracketsPython: Extract numbers from a stringHow to extract a substring using regexFind all occurrences of a substring in PythonFind and extract a number from a stringextract a substring in R according to a patternExtract substring using sedExtract substring with a regular expression

How do conventional missiles fly?

Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?

iPad being using in wall mount battery swollen

What is the idiomatic way to say "clothing fits"?

What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?

Do UK voters know if their MP will be the Speaker of the House?

Assassin's bullet with mercury

Detention in 1997

Expand and Contract

Should I tell management that I intend to leave due to bad software development practices?

Is it inappropriate for a student to attend their mentor's dissertation defense?

What type of content (depth/breadth) is expected for a short presentation for Asst Professor interview in the UK?

Would Slavery Reparations be considered Bills of Attainder and hence Illegal?

Should I cover my bicycle overnight while bikepacking?

Why no variance term in Bayesian logistic regression?

Apex Framework / library for consuming REST services

Short story with a alien planet, government officials must wear exploding medallions

How dangerous is XSS?

Are there any examples of a variable being normally distributed that is *not* due to the Central Limit Theorem?

What mechanic is there to disable a threat instead of killing it?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

One verb to replace 'be a member of' a club

Arrow those variables!

In 'Revenger,' what does 'cove' come from?



json parse extract substring


Split a string by spaces — preserving quoted substrings — in PythonHow can I extract a predetermined range of lines from a text file on Unix?Regular expression to extract text between square bracketsPython: Extract numbers from a stringHow to extract a substring using regexFind all occurrences of a substring in PythonFind and extract a number from a stringextract a substring in R according to a patternExtract substring using sedExtract substring with a regular expression













-2















I am trying to extract credentials client secret from the cloud foundry env json string



cf env myapp


gives the exact following,(not a proper json so thats why i cant use jq)



Getting env variables for app icm in org myorg / space myspace as 
xxyy...
OK



"myenv_env_json":
"http_proxy": "http://mycompany-svr-proxy-qa.mycompany.com:7070",
"https_proxy": "http://mycompany-svr-proxy-qa.mycompany.com:7070",
"no_proxy": "*.mycompany.com"
,
"running_env_json": ,
"system_env_json":
"VCAP_SERVICES":
"user-provided": [

"name": "myapp-parameters",
"instance_name": "myapp-parameters",
"binding_name": null,
"credentials":
"auth-domain": "https://sso.login.run-np.mycompany.com",
"backend-url-other": "https://myservice-other.apps-np.mycompany.com",
"client-secret": "121322332-32322-23232-232-32-23232",
"stage": "mystg",
"backend-url": "https://myservice-other.apps-np.mycompany.com",
"client-secret-other": "121322332-32322-23232-232-32-23232"
,
"syslog_drain_url": "",
"volume_mounts": [],
"label": "user-provided",
"tags": []
,

"name": "appdynamics",
"instance_name": "appdynamics",
"binding_name": null,
"credentials":
"account-access-key": "1213232-232-322-2322323-2323232-311",
"account-name": "customer1",
"application-name": "myenv-dev",
"host-name": "appdx-qa.mycompany.com",
"node-name": "$(ruby -e "require 'json'; a = JSON.parse(ENV['VCAP_APPLICATION']); puts \"#a['application_name']-#-/)[2]:#a['instance_index']\"")",
"port": "9401",
"ssl-enabled": "true",
"tier-name": "$(ruby -e "require 'json'; a = JSON.parse(ENV['VCAP_APPLICATION']); puts \"#a['application_name']-#-/)[2]\"")",
"version": "4.2.7_1"
,
"syslog_drain_url": "",
"volume_mounts": [],
"label": "user-provided",
"tags": []

],
"p-identity": [

"name": "sso",
"instance_name": "sso",
"binding_name": null,
"credentials":
"auth_domain": "https://sso.login.run-np.mycompany.com",
"client_secret": "123232-23232-2323243-242323r3r",
"client_id": "afdvdf-dvdfdd-fgdgdf-d23232"
,
"syslog_drain_url": null,
"volume_mounts": [],
"label": "p-identity",
"provider": null,
"plan": "sso",
"tags": []

]

,
"application_env_json":
"VCAP_APPLICATION":
"cf_api": "https://api.run-np.mycompany.com",
"limits":
"fds": 16384
,
"application_name": "myapp",
"application_uris": [
"myapp-dev.apps-np.mycompany.com"
],
"name": "myapp",
"space_name": "myapp-dev",
"space_id": "392929-23223-2323-2322-2322",
"uris": [
"myapp-dev.apps-np.mycompany.com"
],
"users": null,
"application_id": "fwew78cc-wewc5c-dfd8a7-89d5-fdfefwewb"




User-Provided:
APP_ENV: development
GRANT_TYPE: authorization_code
SSO_AUTO_APPROVED_SCOPES: openid
SSO_IDENTITY_PROVIDERS: mycompany-single-signon
SSO_LAUNCH_URL: https://myapp-dev.apps-np.mycompany.com/
SSO_REDIRECT_URIS: https://myapp-dev.apps-np.mycompany.com/callback,http://myapp-dev.apps-np.mycompany.com/callback
SSO_SCOPES: openid,user_attributes
callback_url: https://myapp-dev.apps-np.mycompany.com/callback
client_secret: secret
client_secret_other: secretother

No running env variables have been set

Staging Environment Variable Groups:
http_proxy: http://myapp-svr-proxy-qa.mycompany.com:7070
https_proxy: http://myapp-svr-proxy-qa.mycompany.com:7070
no_proxy: *.mycompany.com


Here is what i am trying to use, and so far no luck extracting p-identity sub json, what is wrong in my sed



 cf env myapp|sed 's/.*(p-identity[^}].*}).*/1/p'


my expected output should be as follows



"p-identity": [
 











-2















I am trying to extract credentials client secret from the cloud foundry env json string



cf env myapp


gives the exact following,(not a proper json so thats why i cant use jq)



Getting env variables for app icm in org myorg / space myspace as 
xxyy...
OK



"myenv_env_json":
"http_proxy": "http://mycompany-svr-proxy-qa.mycompany.com:7070",
"https_proxy": "http://mycompany-svr-proxy-qa.mycompany.com:7070",
"no_proxy": "*.mycompany.com"
,
"running_env_json": ,
"system_env_json":
"VCAP_SERVICES":
"user-provided": [

"name": "myapp-parameters",
"instance_name": "myapp-parameters",
"binding_name": null,
"credentials":
"auth-domain": "https://sso.login.run-np.mycompany.com",
"backend-url-other": "https://myservice-other.apps-np.mycompany.com",
"client-secret": "121322332-32322-23232-232-32-23232",
"stage": "mystg",
"backend-url": "https://myservice-other.apps-np.mycompany.com",
"client-secret-other": "121322332-32322-23232-232-32-23232"
,
"syslog_drain_url": "",
"volume_mounts": [],
"label": "user-provided",
"tags": []
,

"name": "appdynamics",
"instance_name": "appdynamics",
"binding_name": null,
"credentials":
"account-access-key": "1213232-232-322-2322323-2323232-311",
"account-name": "customer1",
"application-name": "myenv-dev",
"host-name": "appdx-qa.mycompany.com",
"node-name": "$(ruby -e "require 'json'; a = JSON.parse(ENV['VCAP_APPLICATION']); puts \"#a['application_name']-#-/)[2]:#a['instance_index']\"")",
"port": "9401",
"ssl-enabled": "true",
"tier-name": "$(ruby -e "require 'json'; a = JSON.parse(ENV['VCAP_APPLICATION']); puts \"#a['application_name']-#-/)[2]\"")",
"version": "4.2.7_1"
,
"syslog_drain_url": "",
"volume_mounts": [],
"label": "user-provided",
"tags": []

],
"p-identity": [

"name": "sso",
"instance_name": "sso",
"binding_name": null,
"credentials":
"auth_domain": "https://sso.login.run-np.mycompany.com",
"client_secret": "123232-23232-2323243-242323r3r",
"client_id": "afdvdf-dvdfdd-fgdgdf-d23232"
,
"syslog_drain_url": null,
"volume_mounts": [],
"label": "p-identity",
"provider": null,
"plan": "sso",
"tags": []

]

,
"application_env_json":
"VCAP_APPLICATION":
"cf_api": "https://api.run-np.mycompany.com",
"limits":
"fds": 16384
,
"application_name": "myapp",
"application_uris": [
"myapp-dev.apps-np.mycompany.com"
],
"name": "myapp",
"space_name": "myapp-dev",
"space_id": "392929-23223-2323-2322-2322",
"uris": [
"myapp-dev.apps-np.mycompany.com"
],
"users": null,
"application_id": "fwew78cc-wewc5c-dfd8a7-89d5-fdfefwewb"




User-Provided:
APP_ENV: development
GRANT_TYPE: authorization_code
SSO_AUTO_APPROVED_SCOPES: openid
SSO_IDENTITY_PROVIDERS: mycompany-single-signon
SSO_LAUNCH_URL: https://myapp-dev.apps-np.mycompany.com/
SSO_REDIRECT_URIS: https://myapp-dev.apps-np.mycompany.com/callback,http://myapp-dev.apps-np.mycompany.com/callback
SSO_SCOPES: openid,user_attributes
callback_url: https://myapp-dev.apps-np.mycompany.com/callback
client_secret: secret
client_secret_other: secretother

No running env variables have been set

Staging Environment Variable Groups:
http_proxy: http://myapp-svr-proxy-qa.mycompany.com:7070
https_proxy: http://myapp-svr-proxy-qa.mycompany.com:7070
no_proxy: *.mycompany.com


Here is what i am trying to use, and so far no luck extracting p-identity sub json, what is wrong in my sed



 cf env myapp].*}).*/1/p'


my expected output should be as follows



"p-identity": [
improve this question























    regex sed pivotal-cloud-foundry






    share|improve this question















    share|improve this question













    share|improve this question




    share|improve this question








    edited Mar 7 at 22:28







    loveprogramming

















    asked Mar 7 at 22:19









    loveprogrammingloveprogramming

    13




    13






















        2 Answers
        2






        active

        oldest

        votes


















        0














        For your case it may be easier to pipe the output to grep to extract the JSON, then use jq to extract the field that you want, for example:



        cf env myapp | grep -oz '.*' | jq 'your filter here'






        share|improve this answer























        • thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

          – loveprogramming
          Mar 8 at 7:51



















        0














        I found a dirty workaround, may not be efficient but works for now



        cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1





        share|improve this answer























          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053707%2fjson-parse-extract-substring%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          For your case it may be easier to pipe the output to grep to extract the JSON, then use jq to extract the field that you want, for example:



          cf env myapp | grep -oz '.*' | jq 'your filter here'






          share|improve this answer























          • thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

            – loveprogramming
            Mar 8 at 7:51
















          0














          For your case it may be easier to pipe the output to grep to extract the JSON, then use jq to extract the field that you want, for example:



          cf env myapp | grep -oz '.*' | jq 'your filter here'






          share|improve this answer























          • thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

            – loveprogramming
            Mar 8 at 7:51














          0












          0








          0







          For your case it may be easier to pipe the output to grep to extract the JSON, then use jq to extract the field that you want, for example:



          cf env myapp | grep -oz '.*' | jq 'your filter here'






          share|improve this answer













          For your case it may be easier to pipe the output to grep to extract the JSON, then use jq to extract the field that you want, for example:



          cf env myapp | grep -oz '.*' | jq 'your filter here'







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 23:16









          0xAA550xAA55

          815




          815












          • thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

            – loveprogramming
            Mar 8 at 7:51


















          • thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

            – loveprogramming
            Mar 8 at 7:51

















          thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

          – loveprogramming
          Mar 8 at 7:51






          thanks that didnt helped .giving some other values with a key-value.... i found a dirty fix for now . cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1

          – loveprogramming
          Mar 8 at 7:51














          0














          I found a dirty workaround, may not be efficient but works for now



          cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1





          share|improve this answer



























            0














            I found a dirty workaround, may not be efficient but works for now



            cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1





            share|improve this answer

























              0












              0








              0







              I found a dirty workaround, may not be efficient but works for now



              cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1





              share|improve this answer













              I found a dirty workaround, may not be efficient but works for now



              cf env myapp|sed 1,4d|sed -n '/User-Provided:/q;p'|jq -c -r '.VCAP_SERVICES."p-identity"[0].credentials.client_secret'| head -n1






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 8 at 7:54









              loveprogrammingloveprogramming

              13




              13



























                  draft saved

                  draft discarded
















































                  Thanks for contributing an answer to Stack Overflow!


                  • Please be sure to answer the question. Provide details and share your research!

                  But avoid


                  • Asking for help, clarification, or responding to other answers.

                  • Making statements based on opinion; back them up with references or personal experience.

                  To learn more, see our tips on writing great answers.




                  draft saved


                  draft discarded














                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053707%2fjson-parse-extract-substring%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown





















































                  Required, but never shown














                  Required, but never shown












                  Required, but never shown







                  Required, but never shown

































                  Required, but never shown














                  Required, but never shown












                  Required, but never shown







                  Required, but never shown







                  Popular posts from this blog

                  AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                  Алба-Юлія

                  Захаров Федір Захарович