Unable to display data received as object from backend ,What is the best way to add options to a select from as a JS object with jQuery?How do I remove a property from a JavaScript object?How can I display a JavaScript object?Convert form data to JavaScript object with jQueryHow do I remove a key from a JavaScript object?Get JavaScript object from array of objects by value of propertyFrom an array of objects, extract value of a property as arrayHow to pass variables and data from PHP to JavaScript?How to display the json data in ejs template?error in angular js directive when open a modal

All ASCII characters with a given bit count

What makes accurate emulation of old systems a difficult task?

Why doesn't the standard consider a template constructor as a copy constructor?

Apply a different color ramp to subset of categorized symbols in QGIS?

Combinatorics problem, right solution?

Negative Resistance

Drawing a german abacus as in the books of Adam Ries

Could moose/elk survive in the Amazon forest?

What does "function" actually mean in music?

Restricting the options of a lookup field, based on the value of another lookup field?

Why do games have consumables?

Why did Rep. Omar conclude her criticism of US troops with the phrase "NotTodaySatan"?

What does MLD stand for?

Why do real positive eigenvalues result in an unstable system? What about eigenvalues between 0 and 1? or 1?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Creating a chemical industry from a medieval tech level without petroleum

What is the best way to deal with NPC-NPC combat?

Is there any pythonic way to find average of specific tuple elements in array?

Should the Product Owner dictate what info the UI needs to display?

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

Contradiction proof for inequality of P and NP?

Can someone publish a story that happened to you?

Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?

Multiple fireplaces in an apartment building?



Unable to display data received as object from backend ,


What is the best way to add options to a select from as a JS object with jQuery?How do I remove a property from a JavaScript object?How can I display a JavaScript object?Convert form data to JavaScript object with jQueryHow do I remove a key from a JavaScript object?Get JavaScript object from array of objects by value of propertyFrom an array of objects, extract value of a property as arrayHow to pass variables and data from PHP to JavaScript?How to display the json data in ejs template?error in angular js directive when open a modal






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random" , I want to display all the fields inside a modal , When I try to use Object.keys() , this error is thrown - "cannot convert undefined or null to object".



render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">

<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>
</div>
</div>
);



Not Sure what to do as I tried Using Object.keys but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.










share|improve this question
























  • so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?

    – nishant
    Mar 9 at 8:42











  • The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "

    – Sree
    Mar 9 at 9:11

















0















I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random" , I want to display all the fields inside a modal , When I try to use Object.keys() , this error is thrown - "cannot convert undefined or null to object".



render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">

<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>
</div>
</div>
);



Not Sure what to do as I tried Using Object.keys but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.










share|improve this question
























  • so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?

    – nishant
    Mar 9 at 8:42











  • The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "

    – Sree
    Mar 9 at 9:11













0












0








0








I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random" , I want to display all the fields inside a modal , When I try to use Object.keys() , this error is thrown - "cannot convert undefined or null to object".



render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">

<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>
</div>
</div>
);



Not Sure what to do as I tried Using Object.keys but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.










share|improve this question
















I am fetching data from the backend, it has a particular sub-part called headers which further has an additional name:value pairs .
like this - data : headers : name:"Nishant", value:"random" , I want to display all the fields inside a modal , When I try to use Object.keys() , this error is thrown - "cannot convert undefined or null to object".



render()
return(
let request_data = this.props.head // has the entire data
let data = request_data.headers //contains the headers section to be displayed.
<div className="modal-body">
<div className="row">
<div className="col-lg-6">

<div>
// want to display the headers data here
(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>
</div>
</div>
);



Not Sure what to do as I tried Using Object.keys but an error is thrown saying "cannot convert undefined or null to object". Although by Using JSON.stringify() I am getting the result but not in the expected look and feel.







javascript reactjs javascript-objects






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 8:41







nishant

















asked Mar 9 at 7:44









nishantnishant

296




296












  • so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?

    – nishant
    Mar 9 at 8:42











  • The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "

    – Sree
    Mar 9 at 9:11

















  • so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?

    – nishant
    Mar 9 at 8:42











  • The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "

    – Sree
    Mar 9 at 9:11
















so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?

– nishant
Mar 9 at 8:42





so if its "data": "headers": name: "Nishant", value: "random" , how would i have to proceed ?

– nishant
Mar 9 at 8:42













The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "

– Sree
Mar 9 at 9:11





The key value mentioned in the question is not json and hence you get the error. This is a valid json " "data": "headers": "name": "Nishant", "value": "random" "

– Sree
Mar 9 at 9:11












3 Answers
3






active

oldest

votes


















1














Check header is not undefined before get values;



 <div className="col-lg-6">

<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null

(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>





share|improve this answer























  • If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

    – nishant
    Mar 9 at 9:42











  • yes it is working , i used Object.keys instead of Object.values

    – nishant
    Mar 9 at 9:52


















1














render the text in a <pre> tag and use JSON.stringify



<pre>JSON.stringify(request_data.body,null,2)</pre>





share|improve this answer























  • Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

    – nishant
    Mar 9 at 8:59











  • You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

    – Prithwee Das
    Mar 9 at 9:10












  • Oh ok will try that and see ..

    – nishant
    Mar 9 at 9:44


















1














If a valid response is received.
For Example:




"data":
"headers":
"name": "Nishant",
"value": "random"




var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')


The first option will display the value in data object and the second will display the value inside the headers object.



<pre>responseData.data</pre> 
<pre>responseData.data.headers</pre>





share|improve this answer

























  • I tried , i am getting an error message of unexpected termination of JSON input

    – nishant
    Mar 9 at 9:43











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%2f55075150%2funable-to-display-data-received-as-object-from-backend%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Check header is not undefined before get values;



 <div className="col-lg-6">

<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null

(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>





share|improve this answer























  • If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

    – nishant
    Mar 9 at 9:42











  • yes it is working , i used Object.keys instead of Object.values

    – nishant
    Mar 9 at 9:52















1














Check header is not undefined before get values;



 <div className="col-lg-6">

<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null

(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>





share|improve this answer























  • If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

    – nishant
    Mar 9 at 9:42











  • yes it is working , i used Object.keys instead of Object.values

    – nishant
    Mar 9 at 9:52













1












1








1







Check header is not undefined before get values;



 <div className="col-lg-6">

<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null

(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>





share|improve this answer













Check header is not undefined before get values;



 <div className="col-lg-6">

<div>
request_data.header ? Object.values(request_data.header).map(value => value) : null

(request_data.body !== '') ? <div>Body : request_data.body</div> : ''
</div>

</div>






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 9 at 9:20









aseferovaseferov

2,9322714




2,9322714












  • If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

    – nishant
    Mar 9 at 9:42











  • yes it is working , i used Object.keys instead of Object.values

    – nishant
    Mar 9 at 9:52

















  • If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

    – nishant
    Mar 9 at 9:42











  • yes it is working , i used Object.keys instead of Object.values

    – nishant
    Mar 9 at 9:52
















If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

– nishant
Mar 9 at 9:42





If i do that only the value pairs are getting displayed , i need the entire name:value to be displayed .

– nishant
Mar 9 at 9:42













yes it is working , i used Object.keys instead of Object.values

– nishant
Mar 9 at 9:52





yes it is working , i used Object.keys instead of Object.values

– nishant
Mar 9 at 9:52













1














render the text in a <pre> tag and use JSON.stringify



<pre>JSON.stringify(request_data.body,null,2)</pre>





share|improve this answer























  • Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

    – nishant
    Mar 9 at 8:59











  • You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

    – Prithwee Das
    Mar 9 at 9:10












  • Oh ok will try that and see ..

    – nishant
    Mar 9 at 9:44















1














render the text in a <pre> tag and use JSON.stringify



<pre>JSON.stringify(request_data.body,null,2)</pre>





share|improve this answer























  • Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

    – nishant
    Mar 9 at 8:59











  • You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

    – Prithwee Das
    Mar 9 at 9:10












  • Oh ok will try that and see ..

    – nishant
    Mar 9 at 9:44













1












1








1







render the text in a <pre> tag and use JSON.stringify



<pre>JSON.stringify(request_data.body,null,2)</pre>





share|improve this answer













render the text in a <pre> tag and use JSON.stringify



<pre>JSON.stringify(request_data.body,null,2)</pre>






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 9 at 8:47









Prithwee DasPrithwee Das

684510




684510












  • Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

    – nishant
    Mar 9 at 8:59











  • You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

    – Prithwee Das
    Mar 9 at 9:10












  • Oh ok will try that and see ..

    – nishant
    Mar 9 at 9:44

















  • Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

    – nishant
    Mar 9 at 8:59











  • You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

    – Prithwee Das
    Mar 9 at 9:10












  • Oh ok will try that and see ..

    – nishant
    Mar 9 at 9:44
















Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

– nishant
Mar 9 at 8:59





Yes Had , Tried that , although i am getting the requested headers but additional at the start and end are also getting displayed which is not needed .

– nishant
Mar 9 at 8:59













You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

– Prithwee Das
Mar 9 at 9:10






You can slice those from the string that you are getting from JSON.stringify const dataString = JSON.stringify(request_data.body,null,2); <pre>dataString.slice(3, dataString.length-3)</pre>

– Prithwee Das
Mar 9 at 9:10














Oh ok will try that and see ..

– nishant
Mar 9 at 9:44





Oh ok will try that and see ..

– nishant
Mar 9 at 9:44











1














If a valid response is received.
For Example:




"data":
"headers":
"name": "Nishant",
"value": "random"




var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')


The first option will display the value in data object and the second will display the value inside the headers object.



<pre>responseData.data</pre> 
<pre>responseData.data.headers</pre>





share|improve this answer

























  • I tried , i am getting an error message of unexpected termination of JSON input

    – nishant
    Mar 9 at 9:43















1














If a valid response is received.
For Example:




"data":
"headers":
"name": "Nishant",
"value": "random"




var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')


The first option will display the value in data object and the second will display the value inside the headers object.



<pre>responseData.data</pre> 
<pre>responseData.data.headers</pre>





share|improve this answer

























  • I tried , i am getting an error message of unexpected termination of JSON input

    – nishant
    Mar 9 at 9:43













1












1








1







If a valid response is received.
For Example:




"data":
"headers":
"name": "Nishant",
"value": "random"




var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')


The first option will display the value in data object and the second will display the value inside the headers object.



<pre>responseData.data</pre> 
<pre>responseData.data.headers</pre>





share|improve this answer















If a valid response is received.
For Example:




"data":
"headers":
"name": "Nishant",
"value": "random"




var responseData = JSON.parse(' "data": "headers": name: "Nishant", value: "random" ')


The first option will display the value in data object and the second will display the value inside the headers object.



<pre>responseData.data</pre> 
<pre>responseData.data.headers</pre>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 13:17

























answered Mar 9 at 9:17









SreeSree

937922




937922












  • I tried , i am getting an error message of unexpected termination of JSON input

    – nishant
    Mar 9 at 9:43

















  • I tried , i am getting an error message of unexpected termination of JSON input

    – nishant
    Mar 9 at 9:43
















I tried , i am getting an error message of unexpected termination of JSON input

– nishant
Mar 9 at 9:43





I tried , i am getting an error message of unexpected termination of JSON input

– nishant
Mar 9 at 9:43

















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%2f55075150%2funable-to-display-data-received-as-object-from-backend%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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved