# Create json object in flow

**URL:** https://discourse.nodered.org/t/create-json-object-in-flow/7660
**Category:** General
**Created:** [6 February 2019 13:45 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660 "2019-02-06T13:45:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tramanah](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tramanah/32/9122_2.png) [@tramanah](https://discourse.nodered.org/u/tramanah)
#### Post date: [6 February 2019 13:45 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660/1 "2019-02-06T13:45:57Z")

</div>

Hi good day, I am trying to create object in json format, therefore i can call within flow. The issue is in context data (in flow columns its doesn't appear). i am pretty sure all parameters content data. May i know why?

```auto
var stcal = {
    "line_name" : json[0].lineName,
    "line_No" : json[0].line,
    "currpct" : json[0].curPercentage,
    "SHTPLAN" : json[0].shiftPlan,
    "PinStatus" : json[0].OutputPin, //from php input
    "STActual" : json[0].stActual, //STActual    
    "SHTActual" : json[0].shiftActual, //Shift Actual
    "remark" : json[0].remarks
}
flow.set('stcal',stcal);

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [6 February 2019 13:48 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660/2 "2019-02-06T13:48:47Z")

</div>

Hi @tramanah

Can you provide some more details? There's nothing inherently wrong with the code you've shared. But without knowing what your `json` variable is, where it comes from and what it contains, it's hard to suggest anything.

---

<div class="post-metadata">

### Author: ![tramanah](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tramanah/32/9122_2.png) [@tramanah](https://discourse.nodered.org/u/tramanah)
#### Post date: [7 February 2019 00:40 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660/3 "2019-02-07T00:40:01Z")

</div>

flow: - Update STCAL

* * *

var Deviceid = flow.get('Deviceid');

msg.topic = "Select \*from stcalA where deviceID = '"+ Deviceid +"'";

return msg;

* * *

flow : - stcalA json

* * *

var obj = msg.payload;  
var json = JSON.parse(obj);  
var Deviceid = flow.get('Deviceid');  
var SHTActual = flow.get('SHTActual')||0;  
var STActual = flow.get('STActual')||0;

var resetcounter = flow.get('resetcounter');  
var amenddata = flow.get('amenddata');

var Indata = flow.get('Indata'); //![stcal|637x500]  
if(json[0].OutputPin === 'RST MASTER'){  
resetcounter = 1;  
amenddata = 0;  
SHTActual = 0;  
STActual = 0;  
Indata.ATCounter = 0;  
Indata.STCounter = 0;  
json[0].OutputPin = Indata.PinStatus;

```
flow.set('Indata.ATCounter',Indata.ATCounter);
flow.set('Indata.STCounter',Indata.STCounter);

```

}  
else if(json[0].OutputPin === 'AMEND'){  
resetcounter = 0;  
if(amenddata === 1){  
amenddata = 0;  
json[0].OutputPin = Indata.PinStatus;  
}  
else {amenddata = 1;}

```
SHTActual = json[0].shiftActual;
STActual = json[0].stActual;
Indata.ATCounter = json[0].SHTActual;
Indata.STCounter = json[0].STActual;
json[0].OutputPin = Indata.PinStatus;

flow.set('Indata.ATCounter',Indata.ATCounter);
flow.set('Indata.STCounter',Indata.STCounter);

```

}  
else{  
resetcounter = 0;  
amenddata = 0;  
var status = flow.get('Indata.ATCounter')  
if (!status){  
SHTActual = json[0].shiftActual;  
STActual = json[0].stActual;  
}  
else{  
SHTActual = flow.get('Indata.ATCounter');  
STActual = flow.get('Indata.STCounter');  
}  
if(Indata.PinStatus){  
json[0].OutputPin = Indata.PinStatus;  
}  
else{json[0].OutputPin = 'Not\_Assigned';}  
}

flow.set('resetcounter',resetcounter);  
flow.set('amenddata',amenddata);

flow.set('SHTActual',SHTActual);  
flow.set('STActual',STActual);

var stcal = {  
"line\_name" : json[0].lineName,  
"line\_No" : json[0].line,  
"currpct" : json[0].curPercentage,  
"SHTPLAN" : json[0].shiftPlan,  
"PinStatus" : json[0].OutputPin, //from php input  
"STActual" : json[0].stActual, //STActual  
"SHTActual" : json[0].shiftActual, //Shift Actual  
"remark" : json[0].remarks  
}

flow.set('stcal',stcal);

return msg;\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

 ![stcal](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/73b2407e557414c406fd420da45fe96e88fd3f8b.png)

Note: In fact all the tab's are enable while testing in progress.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [7 February 2019 07:56 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660/4 "2019-02-07T07:56:11Z")

</div>

Please read this post [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) and edit your post to fix the formatting of the code you've shared.

Can you also explain in more detail what behaviour you want? We can't reverse engineer 50+ lines of code and guess what you want it to do.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [7 February 2019 11:29 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660/5 "2019-02-07T11:29:44Z")

</div>

You should also add a debug to the output of `JSON` node to show us what the data actually looks like.

---

<div class="post-metadata">

### Author: ![tramanah](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tramanah/32/9122_2.png) [@tramanah](https://discourse.nodered.org/u/tramanah)
#### Post date: [13 February 2019 04:23 UTC](https://discourse.nodered.org/t/create-json-object-in-flow/7660/6 "2019-02-13T04:23:25Z")

</div>

I did isolate the nodes and just focus on node which create json object, seems its working now. Its shows my coding error in another nodes. I will look into that.

Thank you.

 ![prod](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4c65f4635096586c077c1c0623e670dda0cddabc.png)
