Closed labomat closed 6 years ago
At this point in time this module was for simply parsing json and outputting as needed. It is not intended to be a one stop shop for any json data. I would recommend looking into forking/modifying the codebase since it is a very straightforward thing you would like to do.
Also, look at #3 where someone else wants a very specific display and how I modified the code. If you are completely lost, let me know and if I get time I might be able to help out. I do not want to come off as being mean, but making custom json parsers for people takes time and I have other projects to work on.
Please let me know if you think modifying the code is something you would be interested in (great way to learn about js / coding) and provide a solid .json
file as an example. I can definitely help provide snippets and such, but may or may not have time to help you out. Without an example though I cannot actually do anything.
I got some time to work on this in the end this weekend. Here is some info and a bit of knowledge to let you know what I did.
All of the modifications I made were to the MMM-json-feed.js
and the README.md
files.
Please do take a look at my comments I made to my code for this commit. I have added all kinds of info to it so you can learn a bit about what is going on here.
Finally, here is the relevant info on the configuration:
replaceName
: Specify key names to replace in the json. This is an array of arrays [find, replace]
Example: [ ["body", "replaced body"], ["id", "replacedID"] ]
So a full config would look something like this:
{
module: 'MMM-json-feed',
position: 'bottom_bar',
config: {
url: 'http://your.server.json.here/abc.json'
},
replaceName: [
[ "myThingToBeReplaced", "replacedWithThis" ],
[ "and another", "now replaced like so..." ]
]
}
Please let me know if you have any questions and I hope that this is what you were looking for.
Will have a look at it tonight - thank you!
Unfortunately its not working for me. I have this configuratuon:
{
module: 'MMM-json-feed',
position: 'top_right',
config: {
url: 'http://api.luftdaten.info/v1/sensor/8092/',
title: 'Stickoxidwerte Balkon',
updateInterval: '12000',
values: [
'1.timestamp',
'1.sensordatavalues.0.value',
'1.sensordatavalues.1.value',
'0.timestamp',
'0.sensordatavalues.0.value',
'0.sensordatavalues.1.value'
]
},
replaceName: [
[ 'Timestamp:' , 'Zeit:' ],
[ 'Value' , 'Wert']
]
}
`
The names are not replaced. You can see the JSON data there also - behind the api link.
Notice from your json that the keys are named timestamp
and value
, NOT Timestamp
and Value
. Additionally, you did your curly braces incorrectly and you had a colon :
character in Timestamp
. Your config should look like this:
{
module: 'MMM-json-feed',
position: 'top_right',
config: {
url: 'http://api.luftdaten.info/v1/sensor/8092/',
title: 'Stickoxidwerte Balkon',
updateInterval: '12000',
values: [
'1.timestamp',
'1.sensordatavalues.0.value',
'1.sensordatavalues.1.value',
'0.timestamp',
'0.sensordatavalues.0.value',
'0.sensordatavalues.1.value'
],
replaceName: [
['Timestamp', 'Zeit'],
['Value', 'Wert']
]
}
}
To make things easier, I made the parsing case-insensitive. Just pull in the latest and things should work.
Thanks for helping out - now it works!
I want to display an external json feed I cannot alter. Data comes like this: _valuetype | "P1" value | "8.20" and is displayes like this: value: "8.20" I want to display only the value | "8.20" part but replacing the "value" string with my own string for example like this: Air quality: "8.20"
Generally spoken I need a way to replace JSON nodes with custom text - like a localisation.
Can this be done?