Reputation: 111
I have a Json file or string for example:
{
"my-key0": "ke0",
"key-Arr": [
{
"nested-key1": {
"value": "val",
"seqno": 12
},
"nested2": 1
},
{
"dns-sss-qqq": [
{
"some": "aaaaa"
}
]
}
],
"recsize": 459,
"my-obj": {
"my-key1": {
"my-key2": "key2"
}
}
}
My purpose is to replace "-" char to "_" char only in keys in Scala/Java.
In first I thought it can be done with REGEX but the keys can be UNQUOTED and it also can effect on values. What is most efficient way to it?(Performance is matter) I have to process GBs of such records. Thank you
Upvotes: 1
Views: 405
Reputation: 7989
Try jsoniter-scala - it supports kebab-case since v0.17.0 and also it is more efficient in parsing and serialization than jackson-module-scala
.
Here are latest results of benchmarks which compare parsing & serialization performance of jsoniter-scala
vs. jackson-module-scala
, circe
and play-json
libraries using JDK 8.
Also it has ability to parse streaming JSON values and JSON arrays from java.io.InputStream
w/o need of holding all parsed values in the memory.
Extraction of some selected fields or substructures instead of parsing whole message or document is where jsoniter-scala shines.
So try just use it instead of conversion of all your data.
Upvotes: 1