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

Added json string interpolation #132

Closed
wants to merge 4 commits into from
Closed

Added json string interpolation #132

wants to merge 4 commits into from

Conversation

jutley
Copy link

@jutley jutley commented Aug 19, 2014

Using the syntax json"""{"key":$val}""" will automatically parse the string into Json using Parse.parse().

#81

@markhibberd
Copy link
Contributor

I need to look at this a bit deeper before I merge, but some general comments:

  • I think the string coercion of interpolated values is not quite right, my expectation would be they would use an encode json rather than be toString'd - I am not quite sure what the intended behaviour is for complex values here - it looks like it would only work for numbers at the moment scanning the code.
  • There is potential to implement the interpolator as a macro to make decode failures a compile error for literals. Using a macro to implement would possibly help solve the above point as well.

An example of the interpolator via macro technique is here, if you are interested:

@jedesah
Copy link
Contributor

jedesah commented Aug 25, 2014

Yes, @jutley and I have the pleasure of working together and I discussed similar issues with him. We both agree that making this a macro definition would make this project much more complex but also make the resulting interpolator much more useful.

We also discussed how variable interpolation needs to tap into the notion of a JsonCodec to have a smarter behavior than calling the variables toString method.

Jake is going to be working on this project as part of a goal he set for himself of contributing to an open source project written in Scala as part of his internship program here at WhitePages. Looking forward to seing what he comes up with.

@markhibberd
Copy link
Contributor

@jutley @jedesah Awesome, thanks for the help. I think this is definitely heading in the right direction, just probably needs to work with Codecs as you say. To help with the complexity of macro's etc... there are a few generic programming tools in shapeless (that we already depend on), that can sometimes do the same thing without the need to directly macro things.

I am a bit busier than I would like at the moment, so probably can't help too much in the next few weeks - but I would also suggest jumping on irc, there are good people who are often able to point at similar examples in one of the freenode channels: #scalaz / #shapeless / #argonaut.

@xuwei-k
Copy link
Member

xuwei-k commented Dec 19, 2014

There is a library using "macros + string interpolation" https://github.com/maffoo/jsonquote

@travisbrown
Copy link
Contributor

For what it's worth I recently added a macro-based, compile-time JSON string interpolator to circe: circe/circe#162

You've got a parser in the core library and don't need to support Scala.js, so your implementation could be a lot simpler.

@seanparsons seanparsons closed this Oct 8, 2016
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

Successfully merging this pull request may close these issues.

6 participants