Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#294 Would be nice if you could pass a JSON string into a template #304

Closed
Herostwist opened this issue Jun 12, 2019 · 4 comments
Closed

Comments

@Herostwist
Copy link

#294 Would be nice if you could pass a JSON string into a template as well as an object.

@rexm
Copy link
Member

rexm commented Jun 12, 2019

The goal of this project is to provide a .NET implementation of Handlebars - there are great JSON parsers out there to solve that problem.

@rexm rexm closed this as completed Jun 12, 2019
@Herostwist
Copy link
Author

Indeed, but it would be nice to be able to compile the template without having to deserialise the JSON and without having to know what values the template requires.
I was thinking you could use the new JsonDocument in System.Text.Json

If you have a large JSON payload but the template only uses a few values, it makes sense not to deserialise the JSON but to access just those properties. One could obviously use this to generate an anonymous object to then send to the template, but this would mean you need to know what properties the template needs ahead of time. If you could pass in a JSON string to the compiled template, it could use a JsonDocument to extract just the values it needs from the JSON string without having to deserialise it, and without the calling code having to know what values the template needs to access.

If this isn't something you want to consider, is it possible to get a list of JSON properties the compiled template requires. That way, the list could be used to extract just those properties from a large JSON document without knowing ahead of time which values the template requires.

Thanks.

Using the DOM with the new System.Text.Json

@jrmcdona
Copy link

@Herostwist did you figure this out? All of my handlebars context are JSON files. I am trying to figure out how to covert them into format Handlebars.NET will consume. I just started using this today so I am new here but I have a ton of JSON to use.

@oformaniuk
Copy link
Member

See Handlebars.Net.Extension.Json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants