# How to store data in JSON file in Node-RED

**URL:** <https://discourse.nodered.org/t/how-to-store-data-in-json-file-in-node-red/6480>\
**Category:** General\
**Created:** [6 January 2019 23:56 UTC](https://discourse.nodered.org/t/how-to-store-data-in-json-file-in-node-red/6480 "2019-01-06T23:56:57Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [11 January 2019 22:04 UTC](https://discourse.nodered.org/t/how-to-store-data-in-json-file-in-node-red/6480/21 "2019-01-11T22:04:35Z")

</div>

> [@TotallyInformation](#):
>
> If you were using the structure I described, it would tell you how many entries you have at the top level. If you need more complex filters, then there are other ways as mentioned by others.

Agreed. I was trying to address one of the original questions:

> [@hazymat](#):
>
> - count the number of light circuits in a room (in case I add or remove some later)

which I think needs one of those more complex filters.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 January 2019 22:18 UTC](https://discourse.nodered.org/t/how-to-store-data-in-json-file-in-node-red/6480/22 "2019-01-11T22:18:10Z")

</div>

> [@drmibell](#):
>
> > - count the number of light circuits in a room (in case I add or remove some later)
> 
> which I think needs one of those more complex filters.

Sorry, I was in a hurry with that original response. I was actually thinking about other possible ways to restructure the data so that you didn't need to process it as much - such as splitting the top-level by type so that all the lights were on one property. Then, once again, you could use `Object.keys().length` and stick with named properties if you wanted to. But of course, once you get into needing to filter an array or object by a sub-property, you might as well stick with an array so that you can use the filter function.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [11 January 2019 22:26 UTC](https://discourse.nodered.org/t/how-to-store-data-in-json-file-in-node-red/6480/23 "2019-01-11T22:26:42Z")

</div>

> [@hazymat](#):
>
> **Is this a vaguely sensible idea?** Is there a better way?
> 
> Should I work towards creating my own node type to handle this stuff?

It could help to step back from your specific questions and look at the bigger picture. Over the years I've worked with a bunch of home automation packages, open-source and commercial. Each one had a slightly (or wildly) different approach to mapping the real world onto an abstract data structure. Most of the time, you could see how design choices were influenced by factors such as (human) readability, efficiency (of storage or command execution), modifiability, as well as bias toward certain database tools and programming languages. There is also an element of the developer's notion of "usability" -- does it feel "natural" to organize the world this way and does it correspond to the things that happen or are made to happen there.

Regarding what you have so far, if it works for you, great. If it doesn't, change it. Don't lock yourself into anything until you've used it seriously for a while. In terms of publication, I think if you look at the [NR Library](https://flows.nodered.org/?num_pages=1), you'll find that lot of home automation projects have been published as flows rather than custom nodes. That's a good way to get something out there quickly and get feedback without putting a lot of effort into something you haven't done before, unless of course you just want to want to develop a custom node for the fun of it.🤨

[Previous page](https://discourse.nodered.org/t/how-to-store-data-in-json-file-in-node-red/6480.md?page=1)
