将非嵌套的 JSON 字符串转换为嵌套的 JSON 字符串。

huangapple 未分类评论58阅读模式
标题翻译

Take non-nested JSON String and Build Json Nested String

问题

这对我来说很新。我正在从Cassandra表中读取数据。这些数据是通过"select json * ..."查询提取的,但问题在于,该JSON的格式为:

  1. {"acct_ref_nb": 1401040701, "txn_pst_dt": "2020-02-26", "txn_pst_tm": 1934131, "txn_am": 15000.0, ...

每个字段都用引号括起来,后面跟着冒号,然后是值,再加上逗号和下一个字段,依此类推。

我们需要重新格式化它,并创建一个嵌套结构。我们还需要更改字段的名称。因此,您可能会得到类似于以下的内容:

  1. "{
  2. "ccEvent": {
  3. "account": {
  4. "accountReferenceNumber": 1401040701,
  5. "transactionPostDate": "2020-02-26",
  6. "transactionPostTime": 1934131,
  7. "transactionAmount": 15000.0,
  8. ........

是否有首选的库可以实现这一点?即使在高层次上,我都对如何做这个感到完全迷茫。谢谢。

英文翻译

This is very new to me. I am reading data from a cassandra table. This data is being extracted via a "select json * ..." query but here's the thing. The format of that json is

  1. {"acct_ref_nb": 1401040701, "txn_pst_dt": "2020-02-26", "txn_pst_tm": 1934131, "txn_am": 15000.0 ....

Every field is in quotation marks, followed by a colon, followed by the value, then a comma and the next field, so on and so forth.

We need to reformat this and have a nested structure. We also need to change the names of the fields. So you would have something like...

  1. "{
  2. "ccEvent": {
  3. "account": {
  4. "accountReferenceNumber": 1401040701,
  5. "transactionPostDate": "2020-02-26",
  6. "transactionPostTime": 1934131,
  7. "transactionAmount": 15000.0,
  8. ........

Is there a preferred library to do this? I'm literally lost even at a high level on how to do this. Thanks.

huangapple
  • 本文由 发表于 2020年3月4日 05:22:45
  • 转载请务必保留本文链接:https://java.coder-hub.com/60515723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定