dataframe icon indicating copy to clipboard operation
dataframe copied to clipboard

Feature: JSON parse options

Open Jolanrensen opened this issue 2 years ago • 7 comments

Currently we just use Klaxon to read JSON using the default settings. We should allow users to change Klaxon settings.

Jolanrensen avatar Sep 28 '23 14:09 Jolanrensen

From another side, need to do it without expanding any Klaxon API in our public API if it changes in the future

zaleslaw avatar Oct 02 '23 13:10 zaleslaw

That's probably why it was hidden

Jolanrensen avatar Oct 02 '23 13:10 Jolanrensen

Some proxies for basic options will be enough, probably?

zaleslaw avatar Oct 02 '23 13:10 zaleslaw

probably yes. For advanced stuff users can simply parse it using their own parser, export to string and feed it to DF again

Jolanrensen avatar Oct 02 '23 13:10 Jolanrensen

@Jolanrensen is it possible to disable parsing of JSONs and read them as Strings?

dsalv avatar Feb 20 '25 13:02 dsalv

Definitely! It depends a bit from where you want to disable this. If you're reading from CSV, for instance, you can supply a colTypes = mapOf("yourColName" to ColType.String), this will skip parsing completely and makes sure a column remains String.

The second way to do it is a bit less obvious, but also works well. JSON is parsed to DataRow/DataFrame, meaning, if you add parserOptions = ParserOptions(skipTypes = setOf(typeOf<AnyFrame>(), typeOf<AnyRow>())), the result of parsing will never contain a DataRow or DataFrame so JSON will remain String. This can also be done globally by calling DataFrame.parser.addSkipType(...).

Jolanrensen avatar Feb 20 '25 14:02 Jolanrensen

Definitely! It depends a bit from where you want to disable this. If you're reading from CSV, for instance, you can supply a colTypes = mapOf("yourColName" to ColType.String), this will skip parsing completely and makes sure a column remains String.

The second way to do it is a bit less obvious, but also works well. JSON is parsed to DataRow/DataFrame, meaning, if you add parserOptions = ParserOptions(skipTypes = setOf(typeOf<AnyFrame>(), typeOf<AnyRow>())), the result of parsing will never contain a DataRow or DataFrame so JSON will remain String. This can also be done globally by calling DataFrame.parser.addSkipType(...).

Thank you! Second approach looks interesting.

dsalv avatar Feb 21 '25 09:02 dsalv