question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Favored way of making JToken?

See original GitHub issue

Hi!

I have to do a lot of back and forth to convert my events to the JToken type. Since Newtonsoft’s JsonConvert’s default converter serializes fsharp types in a very bloated and unnatural way, I have to use FSharpLu.Json’s serializer (see the difference here: https://github.com/Microsoft/fsharplu/wiki/fsharplu.json#option-type).

However, FSharpLu.Json convert object directly to string – which means I have to take the result of that and parse it with JToken.Parse to get the desired JToken type. That seems like a lot of unnecessary conversion back and forth. Probably not a huge deal for a modern CPU, but still creates a little unnecessary load – especially considering that our app will grow and eventual have a lot of events that needs processing.

So… Is there a way to pass it a string directly without parsing it first with JToken.Parse? Also, when I read the event, I have to do a .ToString() to convert it back to raw json, so that FSharpLu.Json can convert it to an object again.

Also, I’m really curious: How do you guys create Json? Do you use JsonConvert from Newtonsoft? How do you deal with the awkward json it makes for SumTypes & Options types etc.? Is there a better library than FSharpLu.Json? Chiron has zero documentation it seems, and all other json projects look pretty dead 😦 It seems that Json + F# is almost a little unsolved…?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bartelinkcommented, Apr 1, 2019

Assorted asides and red herrings:

0reactions
kunjee17commented, Jan 19, 2020

@drhumlen I guess that issue is solved. As of now it is very much store specific. Like liteDB is having bson value and Servicestack (dapper in future) is having long string (blob) value. While inmemory database is having object.

So, have a look and if there is question to any specific store I guess than we can always continue with that. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting the name / key of a JToken with JSON.net
If the JToken key name is unknown, and you only need the key's Value regardless of name, simply use the JToken.Values() method. The...
Read more >
JToken Methods
Asynchronously creates a JToken from a JsonReader. Load a JToken from a string that contains JSON.
Read more >
JToken.FromObject Method (Object)
The object that will be used to create JToken. Return Value. Type: JToken. A JToken with the value of the specified object. See...
Read more >
JToken Class
Returns a collection of the child tokens of this token, in document order, filtered by the specified type. Public method, CreateReader.
Read more >
JToken.Parse Method (String)
Load a JToken from a string that contains JSON. Namespace: Newtonsoft.Json.Linq Assembly: Newtonsoft.Json (in Newtonsoft.Json.dll) Version: 12.0.1+ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found