Read the statement by Michael Teeuw here.
Trim the fat in a JSON file?
-
@DeathChicken said in Trim the fat in a JSON file?:
I just want the 2.1 output
So the value of the key “price”. I haven’t looked at the module’s code, but I think you have to say “price” instead of “key4”.
values: ["price"]
-
Tried that. It doesn’t work.
The field just doesn’t display any data at all
if i set
values: [""]
it shows
-
Ok, I checked the code of that module,
values: ["price"]
IS the correct setting for the config butgetValue: function(data, value) {...
has an error.getValue: function(data, value) { if (data && value) { var split = value.split("."); var current = data; while (split.length > 0) { // current = current[split.shift()]; // WRONG! current = current[0][split.shift()]; } return current; } return null; },
I’d have written that totally different, but yeah, at the moment, the problem is, that the object it should be looking for is nested within a wrapping object. Add the
[0]
and you should be getting your results.
Edit: Could also be a problem with the received json format. -
Thank you so much.
I wasn’t sure where to add the [0] exactly. But at least I had somethign to play with.
After a couple tries values: [“0.price”] yields output of Price: “2.1” which is clear enough for my needs. -
@doubleT If you think there is an improvement that can be done to that module, perhaps file an issue or PR at the module repo? I’ve been looking at that module and wondering if it’s worthwhile using it, or rather just use something more complete as a template. What do you think?