farling42 / obsidian-import-json

Plug-in for Obsidian.md which will create Notes from JSON files
MIT License
85 stars 5 forks source link

JSON-Handlebarjs helper math does not see variables with numeric values as numbers #55

Closed buttonpushertv closed 8 months ago

buttonpushertv commented 8 months ago

Extracted values from JSON, even when they are number values, do not get passed to the math Handlebar Helpers as numbers. For example, pulling data from a Fantasy Map Generator JSON, the value at pack.burgs[x].population is a number that needs to be multiplied by 1000 to shift it to the correct value.

Using the mustache helper: {{multiply 1000 population}} in a template when importing fails with an error that population is not a number.

Even using a nested helper like: {{multiply 1000 (toFloat population)}} fails with the same error.

I've resorted to using a custom js helper, but is there a different method or way to force a value like population to be interpreted as a number?

farling42 commented 8 months ago

It should be up to your "multiply" helper to decide if the strings being passed to it can be treated as numbers.

buttonpushertv commented 8 months ago

I'm using the built in handlebar helpers referenced on the ReadMe page. How do I tell them to interpret a value as a number? (Using the nested format doesn't work either).

Using a custom helper does work, but I was hoping to use what's already built in, if it can be made to work.

buttonpushertv commented 8 months ago

Oh, and the value that gets passed to my custom helper workaround appears to the function as a numeric value without any need for my helper to convert it to a number type.

Does that mean that the importer is seeing the value type correctly and the mustache math helpers are not interpreting it as a number? (Which is frustrating because I'm constructing it as they show in their examples.)

farling42 commented 8 months ago

I just tried it with the data you provided earlier. Using pack.burgs as the "Field containing the data", I get the correct values when using the handlebars expression

population: {{population}}
population2: {{multiply population 1000}}

image

buttonpushertv commented 8 months ago

Strange. Maybe there's another plugin interfering. I'll see what I can find out by disabling others and troubleshooting.

buttonpushertv commented 8 months ago

Closing this one (since you've determined it works as intended). I'll report back if I discover anything that be conflicting and causing it to not work on my end.

Thanks.