Javascript / Chrome - How to copy an object from the webkit inspector as code









up vote
269
down vote

favorite
66












I am doing a console.log statement in my javascript in order to log a javascript object. I'm wondering if there's a way, once that's done - to copy that object as javascript code. What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server. I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.enter image description here










share|improve this question

















  • 1




    Try using firefox and the option .toSource(). It's easier
    – chepe263
    Apr 24 '12 at 20:18














up vote
269
down vote

favorite
66












I am doing a console.log statement in my javascript in order to log a javascript object. I'm wondering if there's a way, once that's done - to copy that object as javascript code. What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server. I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.enter image description here










share|improve this question

















  • 1




    Try using firefox and the option .toSource(). It's easier
    – chepe263
    Apr 24 '12 at 20:18












up vote
269
down vote

favorite
66









up vote
269
down vote

favorite
66






66





I am doing a console.log statement in my javascript in order to log a javascript object. I'm wondering if there's a way, once that's done - to copy that object as javascript code. What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server. I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.enter image description here










share|improve this question













I am doing a console.log statement in my javascript in order to log a javascript object. I'm wondering if there's a way, once that's done - to copy that object as javascript code. What I'm trying to do is convert an object that was created using ajax to parse an xml feed into a static javascript object so that a file can run locally, without a server. I've included a screenshot of the object in the chrome inspector window so you can see what I'm trying to do.enter image description here







javascript jquery google-chrome object webkit






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 24 '12 at 20:15









mheavers

10.6k45152256




10.6k45152256







  • 1




    Try using firefox and the option .toSource(). It's easier
    – chepe263
    Apr 24 '12 at 20:18












  • 1




    Try using firefox and the option .toSource(). It's easier
    – chepe263
    Apr 24 '12 at 20:18







1




1




Try using firefox and the option .toSource(). It's easier
– chepe263
Apr 24 '12 at 20:18




Try using firefox and the option .toSource(). It's easier
– chepe263
Apr 24 '12 at 20:18












8 Answers
8






active

oldest

votes

















up vote
662
down vote



accepted










  1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.


  2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.


Copy Javascript Object in Chrome DevTools



Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. This is to be expected.






share|improve this answer


















  • 2




    return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
    – Pardeep Jain
    Aug 19 '16 at 6:33






  • 6




    @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
    – Carl
    Aug 23 '16 at 17:57







  • 18




    This just gives [object Object] for me.
    – Ullallulloo
    May 24 '17 at 20:58










  • @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
    – kevnk
    May 24 '17 at 21:06






  • 1




    it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
    – Marwen Trabelsi
    Feb 23 at 14:02

















up vote
37
down vote













Try JSON.stringify(). Copy the resulting string.






share|improve this answer


















  • 6




    I don't see how that would work unless you modify the code that logs it.
    – iConnor
    Nov 10 '13 at 21:27






  • 1




    For some reason this isn't working when I try to stringify a keyboardevent...
    – Thomas W
    Feb 15 '17 at 14:25






  • 2




    I get TypeError: Converting circular structure to JSON
    – Tony Brasunas
    Aug 2 at 17:38


















up vote
22
down vote













You can now accomplish this in Chrome by right clicking on the object and selecting "Store as Global Variable": http://www.youtube.com/watch?v=qALFiTlVWdg



enter image description here






share|improve this answer


















  • 1




    As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
    – Walter Roman
    Jan 13 '15 at 0:20






  • 1




    @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
    – PatS
    Sep 15 at 16:01


















up vote
21
down vote













You can copy an object to your clip board using copy(JSON.stringify(Object_Name)); in the console.



Eg:- Paste the below code in your console and press enter then try to paste(ctrl+V) it some where else and you will get "name":"Daniel","age":25



var profile = 
name: "Daniel",
age: 25
;

copy(JSON.stringify(profile));





share|improve this answer
















  • 9




    Doesn't work with DOM nodes, window or any other object that it's circular
    – Carles Alcolea
    Dec 27 '16 at 3:18










  • By far the easiest solution for a large but simple object.
    – Hersheezy
    Jan 18 '17 at 15:30

















up vote
8
down vote













Follow the following steps:



  1. Output the object with console.log from your code, like so: console.log(myObject)

  2. Right click on the object and click "Store as Global Object". Chrome would print the name of the variable at this point. Let's assume it's called "temp1".

  3. In the console, type: JSON.stringify(temp1).

  4. At this point you will see the entire JSON object as a string that you can copy/paste.

  5. You can use online tools like http://www.jsoneditoronline.org/ to prettify your string at this point.





share|improve this answer






















  • Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
    – heroin
    Jul 10 '16 at 13:41






  • 1




    Get error Failed to save to temp variable.
    – JoeTidee
    Sep 27 '17 at 15:13










  • @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
    – Tony Brasunas
    Aug 2 at 17:28

















up vote
6
down vote













If you've sent the object over a request you can copy it from the Chrome -> Network tab.



Request Payload - > View Source



enter image description here



enter image description here






share|improve this answer


















  • 2




    After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
    – Muhammad Hassan
    Oct 20 '16 at 8:56

















up vote
0
down vote













Using "Store as a Global Variable" works, but it only gets the final instance of the object, and not the moment the object is being logged (since you're likely wanting to compare changes to the object as they happen). To get the object at its exact point in time of being modified, I use this...



function logObject(object) 
console.info(JSON.stringify(object).replace(/,/g, ",n"));



Call it like so...



logObject(puzzle);


You may want to remove the .replace(/./g, ",n") regex if your data happens to have comma's in it.






share|improve this answer



























    up vote
    0
    down vote













    So,. I had this issue,. except I got [object object]



    I'm sure you could do this with recursion but this worked for me:



    Here is what I did in my console:



    var object_that_is_not_shallow = $("all_obects_with_this_class_name");
    var str = '';
    object_that_is_not_shallow.map(function(_,e)
    str += $(e).html();
    );
    copy(str);


    Then paste into your editor.






    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',
      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%2f10305365%2fjavascript-chrome-how-to-copy-an-object-from-the-webkit-inspector-as-code%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      8 Answers
      8






      active

      oldest

      votes








      8 Answers
      8






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      662
      down vote



      accepted










      1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.


      2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.


      Copy Javascript Object in Chrome DevTools



      Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. This is to be expected.






      share|improve this answer


















      • 2




        return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
        – Pardeep Jain
        Aug 19 '16 at 6:33






      • 6




        @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
        – Carl
        Aug 23 '16 at 17:57







      • 18




        This just gives [object Object] for me.
        – Ullallulloo
        May 24 '17 at 20:58










      • @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
        – kevnk
        May 24 '17 at 21:06






      • 1




        it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
        – Marwen Trabelsi
        Feb 23 at 14:02














      up vote
      662
      down vote



      accepted










      1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.


      2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.


      Copy Javascript Object in Chrome DevTools



      Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. This is to be expected.






      share|improve this answer


















      • 2




        return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
        – Pardeep Jain
        Aug 19 '16 at 6:33






      • 6




        @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
        – Carl
        Aug 23 '16 at 17:57







      • 18




        This just gives [object Object] for me.
        – Ullallulloo
        May 24 '17 at 20:58










      • @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
        – kevnk
        May 24 '17 at 21:06






      • 1




        it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
        – Marwen Trabelsi
        Feb 23 at 14:02












      up vote
      662
      down vote



      accepted







      up vote
      662
      down vote



      accepted






      1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.


      2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.


      Copy Javascript Object in Chrome DevTools



      Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. This is to be expected.






      share|improve this answer














      1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.


      2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.


      Copy Javascript Object in Chrome DevTools



      Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. This is to be expected.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Feb 23 at 18:58

























      answered Aug 5 '14 at 13:54









      kevnk

      7,17711421




      7,17711421







      • 2




        return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
        – Pardeep Jain
        Aug 19 '16 at 6:33






      • 6




        @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
        – Carl
        Aug 23 '16 at 17:57







      • 18




        This just gives [object Object] for me.
        – Ullallulloo
        May 24 '17 at 20:58










      • @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
        – kevnk
        May 24 '17 at 21:06






      • 1




        it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
        – Marwen Trabelsi
        Feb 23 at 14:02












      • 2




        return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
        – Pardeep Jain
        Aug 19 '16 at 6:33






      • 6




        @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
        – Carl
        Aug 23 '16 at 17:57







      • 18




        This just gives [object Object] for me.
        – Ullallulloo
        May 24 '17 at 20:58










      • @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
        – kevnk
        May 24 '17 at 21:06






      • 1




        it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
        – Marwen Trabelsi
        Feb 23 at 14:02







      2




      2




      return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
      – Pardeep Jain
      Aug 19 '16 at 6:33




      return undefined in chrome Version 49.0.2623.87 (64-bit) ? why >?
      – Pardeep Jain
      Aug 19 '16 at 6:33




      6




      6




      @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
      – Carl
      Aug 23 '16 at 17:57





      @PardeepJain - that is expected from the copy() method because there is nothing to return. The data should be in your clipboard.
      – Carl
      Aug 23 '16 at 17:57





      18




      18




      This just gives [object Object] for me.
      – Ullallulloo
      May 24 '17 at 20:58




      This just gives [object Object] for me.
      – Ullallulloo
      May 24 '17 at 20:58












      @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
      – kevnk
      May 24 '17 at 21:06




      @Ullallulloo try logging out with JSON.stringify like this: stackoverflow.com/a/4293047/622287
      – kevnk
      May 24 '17 at 21:06




      1




      1




      it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
      – Marwen Trabelsi
      Feb 23 at 14:02




      it works only if you have a shallow JS object, if you have recursive deep object then will you ll get [Object Object] - that is expected
      – Marwen Trabelsi
      Feb 23 at 14:02












      up vote
      37
      down vote













      Try JSON.stringify(). Copy the resulting string.






      share|improve this answer


















      • 6




        I don't see how that would work unless you modify the code that logs it.
        – iConnor
        Nov 10 '13 at 21:27






      • 1




        For some reason this isn't working when I try to stringify a keyboardevent...
        – Thomas W
        Feb 15 '17 at 14:25






      • 2




        I get TypeError: Converting circular structure to JSON
        – Tony Brasunas
        Aug 2 at 17:38















      up vote
      37
      down vote













      Try JSON.stringify(). Copy the resulting string.






      share|improve this answer


















      • 6




        I don't see how that would work unless you modify the code that logs it.
        – iConnor
        Nov 10 '13 at 21:27






      • 1




        For some reason this isn't working when I try to stringify a keyboardevent...
        – Thomas W
        Feb 15 '17 at 14:25






      • 2




        I get TypeError: Converting circular structure to JSON
        – Tony Brasunas
        Aug 2 at 17:38













      up vote
      37
      down vote










      up vote
      37
      down vote









      Try JSON.stringify(). Copy the resulting string.






      share|improve this answer














      Try JSON.stringify(). Copy the resulting string.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Oct 7 '16 at 13:04

























      answered Apr 24 '12 at 20:19









      Salman A

      171k65328413




      171k65328413







      • 6




        I don't see how that would work unless you modify the code that logs it.
        – iConnor
        Nov 10 '13 at 21:27






      • 1




        For some reason this isn't working when I try to stringify a keyboardevent...
        – Thomas W
        Feb 15 '17 at 14:25






      • 2




        I get TypeError: Converting circular structure to JSON
        – Tony Brasunas
        Aug 2 at 17:38













      • 6




        I don't see how that would work unless you modify the code that logs it.
        – iConnor
        Nov 10 '13 at 21:27






      • 1




        For some reason this isn't working when I try to stringify a keyboardevent...
        – Thomas W
        Feb 15 '17 at 14:25






      • 2




        I get TypeError: Converting circular structure to JSON
        – Tony Brasunas
        Aug 2 at 17:38








      6




      6




      I don't see how that would work unless you modify the code that logs it.
      – iConnor
      Nov 10 '13 at 21:27




      I don't see how that would work unless you modify the code that logs it.
      – iConnor
      Nov 10 '13 at 21:27




      1




      1




      For some reason this isn't working when I try to stringify a keyboardevent...
      – Thomas W
      Feb 15 '17 at 14:25




      For some reason this isn't working when I try to stringify a keyboardevent...
      – Thomas W
      Feb 15 '17 at 14:25




      2




      2




      I get TypeError: Converting circular structure to JSON
      – Tony Brasunas
      Aug 2 at 17:38





      I get TypeError: Converting circular structure to JSON
      – Tony Brasunas
      Aug 2 at 17:38











      up vote
      22
      down vote













      You can now accomplish this in Chrome by right clicking on the object and selecting "Store as Global Variable": http://www.youtube.com/watch?v=qALFiTlVWdg



      enter image description here






      share|improve this answer


















      • 1




        As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
        – Walter Roman
        Jan 13 '15 at 0:20






      • 1




        @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
        – PatS
        Sep 15 at 16:01















      up vote
      22
      down vote













      You can now accomplish this in Chrome by right clicking on the object and selecting "Store as Global Variable": http://www.youtube.com/watch?v=qALFiTlVWdg



      enter image description here






      share|improve this answer


















      • 1




        As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
        – Walter Roman
        Jan 13 '15 at 0:20






      • 1




        @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
        – PatS
        Sep 15 at 16:01













      up vote
      22
      down vote










      up vote
      22
      down vote









      You can now accomplish this in Chrome by right clicking on the object and selecting "Store as Global Variable": http://www.youtube.com/watch?v=qALFiTlVWdg



      enter image description here






      share|improve this answer














      You can now accomplish this in Chrome by right clicking on the object and selecting "Store as Global Variable": http://www.youtube.com/watch?v=qALFiTlVWdg



      enter image description here







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 22 at 21:05

























      answered Jun 12 '14 at 19:37









      David Calhoun

      4,02131919




      4,02131919







      • 1




        As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
        – Walter Roman
        Jan 13 '15 at 0:20






      • 1




        @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
        – PatS
        Sep 15 at 16:01













      • 1




        As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
        – Walter Roman
        Jan 13 '15 at 0:20






      • 1




        @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
        – PatS
        Sep 15 at 16:01








      1




      1




      As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
      – Walter Roman
      Jan 13 '15 at 0:20




      As of Version 39.0.2171.95, the "Store as Global Variable" option is not available when inspecting Android devices with Chrome.
      – Walter Roman
      Jan 13 '15 at 0:20




      1




      1




      @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
      – PatS
      Sep 15 at 16:01





      @David Calhoun, I voted for your answer. It looks like your answer was posted June 12, 2014 and the one accepted was Aug 5, 2014, largely taking exactly what you had. I have to admit that he mentions temp1 where your answer only shows it in your video, so maybe that's why the other answer was accepted. Best wishes.
      – PatS
      Sep 15 at 16:01











      up vote
      21
      down vote













      You can copy an object to your clip board using copy(JSON.stringify(Object_Name)); in the console.



      Eg:- Paste the below code in your console and press enter then try to paste(ctrl+V) it some where else and you will get "name":"Daniel","age":25



      var profile = 
      name: "Daniel",
      age: 25
      ;

      copy(JSON.stringify(profile));





      share|improve this answer
















      • 9




        Doesn't work with DOM nodes, window or any other object that it's circular
        – Carles Alcolea
        Dec 27 '16 at 3:18










      • By far the easiest solution for a large but simple object.
        – Hersheezy
        Jan 18 '17 at 15:30














      up vote
      21
      down vote













      You can copy an object to your clip board using copy(JSON.stringify(Object_Name)); in the console.



      Eg:- Paste the below code in your console and press enter then try to paste(ctrl+V) it some where else and you will get "name":"Daniel","age":25



      var profile = 
      name: "Daniel",
      age: 25
      ;

      copy(JSON.stringify(profile));





      share|improve this answer
















      • 9




        Doesn't work with DOM nodes, window or any other object that it's circular
        – Carles Alcolea
        Dec 27 '16 at 3:18










      • By far the easiest solution for a large but simple object.
        – Hersheezy
        Jan 18 '17 at 15:30












      up vote
      21
      down vote










      up vote
      21
      down vote









      You can copy an object to your clip board using copy(JSON.stringify(Object_Name)); in the console.



      Eg:- Paste the below code in your console and press enter then try to paste(ctrl+V) it some where else and you will get "name":"Daniel","age":25



      var profile = 
      name: "Daniel",
      age: 25
      ;

      copy(JSON.stringify(profile));





      share|improve this answer












      You can copy an object to your clip board using copy(JSON.stringify(Object_Name)); in the console.



      Eg:- Paste the below code in your console and press enter then try to paste(ctrl+V) it some where else and you will get "name":"Daniel","age":25



      var profile = 
      name: "Daniel",
      age: 25
      ;

      copy(JSON.stringify(profile));






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered May 21 '14 at 7:40









      Sudharshan

      1,36111219




      1,36111219







      • 9




        Doesn't work with DOM nodes, window or any other object that it's circular
        – Carles Alcolea
        Dec 27 '16 at 3:18










      • By far the easiest solution for a large but simple object.
        – Hersheezy
        Jan 18 '17 at 15:30












      • 9




        Doesn't work with DOM nodes, window or any other object that it's circular
        – Carles Alcolea
        Dec 27 '16 at 3:18










      • By far the easiest solution for a large but simple object.
        – Hersheezy
        Jan 18 '17 at 15:30







      9




      9




      Doesn't work with DOM nodes, window or any other object that it's circular
      – Carles Alcolea
      Dec 27 '16 at 3:18




      Doesn't work with DOM nodes, window or any other object that it's circular
      – Carles Alcolea
      Dec 27 '16 at 3:18












      By far the easiest solution for a large but simple object.
      – Hersheezy
      Jan 18 '17 at 15:30




      By far the easiest solution for a large but simple object.
      – Hersheezy
      Jan 18 '17 at 15:30










      up vote
      8
      down vote













      Follow the following steps:



      1. Output the object with console.log from your code, like so: console.log(myObject)

      2. Right click on the object and click "Store as Global Object". Chrome would print the name of the variable at this point. Let's assume it's called "temp1".

      3. In the console, type: JSON.stringify(temp1).

      4. At this point you will see the entire JSON object as a string that you can copy/paste.

      5. You can use online tools like http://www.jsoneditoronline.org/ to prettify your string at this point.





      share|improve this answer






















      • Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
        – heroin
        Jul 10 '16 at 13:41






      • 1




        Get error Failed to save to temp variable.
        – JoeTidee
        Sep 27 '17 at 15:13










      • @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
        – Tony Brasunas
        Aug 2 at 17:28














      up vote
      8
      down vote













      Follow the following steps:



      1. Output the object with console.log from your code, like so: console.log(myObject)

      2. Right click on the object and click "Store as Global Object". Chrome would print the name of the variable at this point. Let's assume it's called "temp1".

      3. In the console, type: JSON.stringify(temp1).

      4. At this point you will see the entire JSON object as a string that you can copy/paste.

      5. You can use online tools like http://www.jsoneditoronline.org/ to prettify your string at this point.





      share|improve this answer






















      • Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
        – heroin
        Jul 10 '16 at 13:41






      • 1




        Get error Failed to save to temp variable.
        – JoeTidee
        Sep 27 '17 at 15:13










      • @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
        – Tony Brasunas
        Aug 2 at 17:28












      up vote
      8
      down vote










      up vote
      8
      down vote









      Follow the following steps:



      1. Output the object with console.log from your code, like so: console.log(myObject)

      2. Right click on the object and click "Store as Global Object". Chrome would print the name of the variable at this point. Let's assume it's called "temp1".

      3. In the console, type: JSON.stringify(temp1).

      4. At this point you will see the entire JSON object as a string that you can copy/paste.

      5. You can use online tools like http://www.jsoneditoronline.org/ to prettify your string at this point.





      share|improve this answer














      Follow the following steps:



      1. Output the object with console.log from your code, like so: console.log(myObject)

      2. Right click on the object and click "Store as Global Object". Chrome would print the name of the variable at this point. Let's assume it's called "temp1".

      3. In the console, type: JSON.stringify(temp1).

      4. At this point you will see the entire JSON object as a string that you can copy/paste.

      5. You can use online tools like http://www.jsoneditoronline.org/ to prettify your string at this point.






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 2 '17 at 3:20









      HoldOffHunger

      3,53121744




      3,53121744










      answered Jun 9 '15 at 0:57









      sufinawaz

      2,7601821




      2,7601821











      • Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
        – heroin
        Jul 10 '16 at 13:41






      • 1




        Get error Failed to save to temp variable.
        – JoeTidee
        Sep 27 '17 at 15:13










      • @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
        – Tony Brasunas
        Aug 2 at 17:28
















      • Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
        – heroin
        Jul 10 '16 at 13:41






      • 1




        Get error Failed to save to temp variable.
        – JoeTidee
        Sep 27 '17 at 15:13










      • @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
        – Tony Brasunas
        Aug 2 at 17:28















      Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
      – heroin
      Jul 10 '16 at 13:41




      Step with JSON.stringify(temp1) could affect to a long time execution if object is big.
      – heroin
      Jul 10 '16 at 13:41




      1




      1




      Get error Failed to save to temp variable.
      – JoeTidee
      Sep 27 '17 at 15:13




      Get error Failed to save to temp variable.
      – JoeTidee
      Sep 27 '17 at 15:13












      @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
      – Tony Brasunas
      Aug 2 at 17:28




      @JoeTidee I had the same issue, but I set up a debugger statement and then retrieved my var directly from the console at the breakpoint.
      – Tony Brasunas
      Aug 2 at 17:28










      up vote
      6
      down vote













      If you've sent the object over a request you can copy it from the Chrome -> Network tab.



      Request Payload - > View Source



      enter image description here



      enter image description here






      share|improve this answer


















      • 2




        After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
        – Muhammad Hassan
        Oct 20 '16 at 8:56














      up vote
      6
      down vote













      If you've sent the object over a request you can copy it from the Chrome -> Network tab.



      Request Payload - > View Source



      enter image description here



      enter image description here






      share|improve this answer


















      • 2




        After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
        – Muhammad Hassan
        Oct 20 '16 at 8:56












      up vote
      6
      down vote










      up vote
      6
      down vote









      If you've sent the object over a request you can copy it from the Chrome -> Network tab.



      Request Payload - > View Source



      enter image description here



      enter image description here






      share|improve this answer














      If you've sent the object over a request you can copy it from the Chrome -> Network tab.



      Request Payload - > View Source



      enter image description here



      enter image description here







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 9 at 19:06

























      answered Sep 12 '14 at 16:51









      Christopher Marshall

      8,47394181




      8,47394181







      • 2




        After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
        – Muhammad Hassan
        Oct 20 '16 at 8:56












      • 2




        After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
        – Muhammad Hassan
        Oct 20 '16 at 8:56







      2




      2




      After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
      – Muhammad Hassan
      Oct 20 '16 at 8:56




      After copying parsed payload, you can format json from jsonformatter.curiousconcept.com.
      – Muhammad Hassan
      Oct 20 '16 at 8:56










      up vote
      0
      down vote













      Using "Store as a Global Variable" works, but it only gets the final instance of the object, and not the moment the object is being logged (since you're likely wanting to compare changes to the object as they happen). To get the object at its exact point in time of being modified, I use this...



      function logObject(object) 
      console.info(JSON.stringify(object).replace(/,/g, ",n"));



      Call it like so...



      logObject(puzzle);


      You may want to remove the .replace(/./g, ",n") regex if your data happens to have comma's in it.






      share|improve this answer
























        up vote
        0
        down vote













        Using "Store as a Global Variable" works, but it only gets the final instance of the object, and not the moment the object is being logged (since you're likely wanting to compare changes to the object as they happen). To get the object at its exact point in time of being modified, I use this...



        function logObject(object) 
        console.info(JSON.stringify(object).replace(/,/g, ",n"));



        Call it like so...



        logObject(puzzle);


        You may want to remove the .replace(/./g, ",n") regex if your data happens to have comma's in it.






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          Using "Store as a Global Variable" works, but it only gets the final instance of the object, and not the moment the object is being logged (since you're likely wanting to compare changes to the object as they happen). To get the object at its exact point in time of being modified, I use this...



          function logObject(object) 
          console.info(JSON.stringify(object).replace(/,/g, ",n"));



          Call it like so...



          logObject(puzzle);


          You may want to remove the .replace(/./g, ",n") regex if your data happens to have comma's in it.






          share|improve this answer












          Using "Store as a Global Variable" works, but it only gets the final instance of the object, and not the moment the object is being logged (since you're likely wanting to compare changes to the object as they happen). To get the object at its exact point in time of being modified, I use this...



          function logObject(object) 
          console.info(JSON.stringify(object).replace(/,/g, ",n"));



          Call it like so...



          logObject(puzzle);


          You may want to remove the .replace(/./g, ",n") regex if your data happens to have comma's in it.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 1 '17 at 21:12









          HoldOffHunger

          3,53121744




          3,53121744




















              up vote
              0
              down vote













              So,. I had this issue,. except I got [object object]



              I'm sure you could do this with recursion but this worked for me:



              Here is what I did in my console:



              var object_that_is_not_shallow = $("all_obects_with_this_class_name");
              var str = '';
              object_that_is_not_shallow.map(function(_,e)
              str += $(e).html();
              );
              copy(str);


              Then paste into your editor.






              share|improve this answer
























                up vote
                0
                down vote













                So,. I had this issue,. except I got [object object]



                I'm sure you could do this with recursion but this worked for me:



                Here is what I did in my console:



                var object_that_is_not_shallow = $("all_obects_with_this_class_name");
                var str = '';
                object_that_is_not_shallow.map(function(_,e)
                str += $(e).html();
                );
                copy(str);


                Then paste into your editor.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  So,. I had this issue,. except I got [object object]



                  I'm sure you could do this with recursion but this worked for me:



                  Here is what I did in my console:



                  var object_that_is_not_shallow = $("all_obects_with_this_class_name");
                  var str = '';
                  object_that_is_not_shallow.map(function(_,e)
                  str += $(e).html();
                  );
                  copy(str);


                  Then paste into your editor.






                  share|improve this answer












                  So,. I had this issue,. except I got [object object]



                  I'm sure you could do this with recursion but this worked for me:



                  Here is what I did in my console:



                  var object_that_is_not_shallow = $("all_obects_with_this_class_name");
                  var str = '';
                  object_that_is_not_shallow.map(function(_,e)
                  str += $(e).html();
                  );
                  copy(str);


                  Then paste into your editor.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 9 at 1:22









                  twalow

                  11




                  11



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10305365%2fjavascript-chrome-how-to-copy-an-object-from-the-webkit-inspector-as-code%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

                      Kleinkühnau

                      Makov (Slowakei)

                      Deutsches Schauspielhaus