# JSON to file weird output

**URL:** <https://forums.losant.com/t/json-to-file-weird-output/4455>\
**Category:** Help\
**Tags:** workflow\
**Created:** [April 11, 2022, 6:52am UTC](https://forums.losant.com/t/json-to-file-weird-output/4455 "2022-04-11T06:52:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [April 11, 2022, 6:52am UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/1 "2022-04-11T06:52:41Z")

</div>

Hi there,  
I am doing a simple web to file stream:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/9/967289ad7e7fcee9da81fe8a5a3cd32661d16fd7.png)

All I get in the file is a string:

> [object Object]

Check the output here: [https://files.onlosant.com/6253be33e5d19b4a80bb49b8/decoy/decoy.json](https://files.onlosant.com/6253be33e5d19b4a80bb49b8/decoy/decoy.json)

---

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [April 11, 2022, 6:56am UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/2 "2022-04-11T06:56:34Z")

</div>

Okay I needed to add the JSON encode block, I assumed it was automatically serializing the objects.  
But now I discovered another issue, how can I just add new lines for each execution?  
There should be an option called “append”

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/c/c1963f0862b45c4218cae3f4a296e984f4b58251.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [April 11, 2022, 12:43pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/3 "2022-04-11T12:43:33Z")

</div>

At this time we do not have an option to append to an existing file in that node, but I will make a feature request to get that added.

As a workaround, you could …

- Use an [HTTP Node](https://docs.losant.com/workflows/data/http/) to fetch the existing file.
- Use an Object Node, Array Node, Mutate Node, or Function Node (depending on the format of the current file, the data to be appended, and your comfort level with writing JavaScript) to append the next JSON manually.
- Use the File: Create Node to overwrite the old file with the manipulated data.

---

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [April 11, 2022, 4:58pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/4 "2022-04-11T16:58:27Z")

</div>

Yes I thought about that workaround or add a new row into a database with JSON serialized as string type?

---

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [April 11, 2022, 5:05pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/5 "2022-04-11T17:05:30Z")

</div>

@Paolo_Proxy,

If by `database` you mean a [Data Table](https://docs.losant.com/data-tables/overview/), then the string type has a limit of [768 Characters](https://docs.losant.com/data-tables/overview/#column-data-types), which may not work for your use case.

Thank you,  
Heath

---

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [April 11, 2022, 8:01pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/6 "2022-04-11T20:01:00Z")

</div>

Ah yes that is a bit small for a json payload agreed.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [April 11, 2022, 8:21pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/7 "2022-04-11T20:21:12Z")

</div>

Losant Data Tables are designed for relatively static data sets. Something like a table that maps fault codes to their description and other meta data.

Data Tables are backed by a database optimized “write light” and “read heavy”. This means data tables can be queried at high rates, but you’ll notice scalability issues if you attempt to continually insert or update data.

If you do want to continually insert data into a database, the recommended approach would be to connect to a managed cloud DB on Azure, AWS, or Google.

For Azure, we’ve got a [guide for using MSSQL](https://www.losant.com/blog/how-to-connect-to-your-azure-mssql-database-with-losant).

For Google BigQuery, we’ve got the built-in [GCP: BigQuery Node](https://docs.losant.com/workflows/data/google-big-query/) and a guide on using it as a [Warm Storage solution](https://docs.losant.com/guides/how-to-use-google-bigquery-as-warm-storage-with-Losant/).

For AWS, I’d recommend using the [AWS Lambda Node](https://docs.losant.com/workflows/data/aws-lambda/) to invoke Lambda functions, which in turn query data from something like [AWS RDS](https://aws.amazon.com/rds/sqlserver/).

If the data you’re receiving is time series data and related to a device, then it should be stored on [Device Attributes](https://docs.losant.com/devices/attributes/). Behind the scenes, all data reported to a device attribute is stored in a time-series database.

---

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [April 13, 2022, 10:46am UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/8 "2022-04-13T10:46:01Z")

</div>

Thanks for the details, this is very informative.  
The original idea behind the file based JSON output is just a quick way to log the data and then write a proper workflow which will store it in the device status.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [April 14, 2022, 8:16pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/9 "2022-04-14T20:16:41Z")

</div>

That makes sense. You could look at [Blob Attributes](https://docs.losant.com/devices/blobs/).

If you want to store an object from the payload as a blob attribute, you can do so with a single, nested, template in the [Device State Node](https://docs.losant.com/workflows/outputs/device-state/).

```nohighlight
attributeName = {{encodeBase64 (jsonEncode data)}}

```

Behind the scenes, the actual blob data is securely stored in a cloud storage bucket. What’s put in the time-series database is a pointer to the location in the bucket.

In most cases, when you want to access the blob data, the platform generates a timed URL where it can be downloaded and accessed through whatever mechanism you require.

---

<div class="post-metadata">

**Author:** ![Gitanjali\_Apet](https://avatars.discourse-cdn.com/v4/letter/g/c37758/32.png) [@Gitanjali\_Apet](https://forums.losant.com/u/Gitanjali_Apet)\
**Post date:** [June 1, 2022, 3:58pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/10 "2022-06-01T15:58:47Z")

</div>

**all data reported to a device attribute is stored in a time-series database.** \>\> Can i retrieve the data stored in time series database?For how much time period data stores in that database?  
Is it a good solution for long term data storage?

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [June 1, 2022, 5:23pm UTC](https://forums.losant.com/t/json-to-file-weird-output/4455/11 "2022-06-01T17:23:44Z")

</div>

> [@Gitanjali\_Apet](#):
>
> Can i retrieve the data stored in time series database?

Yes, data can [exported as CSV](https://docs.losant.com/devices/overview/#request-data-export). You can export data for a single device, or perform a [bulk export for multiple devices](https://docs.losant.com/devices/bulk-actions/#request-data-export).

> [@Gitanjali\_Apet](#):
>
> For how much time period data stores in that database?

This is based on the data retention period in your license. For sandbox accounts, the data retention is 30 days. For licensed organization, the default data retention is 6 months, however many customers choose to increase that to one year.

> [@Gitanjali\_Apet](#):
>
> Is it a good solution for long term data storage?

The time series database is not a good solution for long term data storage. Losant does support automatic [data archiving](https://docs.losant.com/applications/archiving/#device-data) to your own cloud storage bucket. Another solution is to use something like Google BigQuery or equivalent data warehouse on other cloud vendors. We’ve got a guide on using BigQuery here:

> **[How To Use Google BigQuery as Warm Storage With Losant](https://docs.losant.com/guides/how-to-use-google-bigquery-as-warm-storage-with-Losant/)**
>
> Follow along for a walkthrough of setting up Google BigQuery as warm storage with Losant.
