Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

JOLT prefix soup example with an array of objects as input

I am looking at the prefix soup example from jolt-demo.appspot, which seems to be almost exactly what I need however I made a minor modification on the input to have multiple objects in an array, then I changed the spec to have * wildcard to account for the array and the result is not exactly how I need it. I'm obviously missing something fundamental but I don't know what. Any help would be greatly appreciated.

Input JSON

[
  {
    "rating-primary": 1,
    "rating-Price": 2,
    "rating-Design": 4,
    "rating-RatingDimension3": 1
  },
  {
    "rating-primary": 7,
    "rating-Price": 8,
    "rating-Design": 9,
    "rating-RatingDimension3": 10
  }
]

Spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "rating-primary": "Rating",
        "rating-*": "SecondaryRatings.&(0,1)"
      }
    }
  }
]

Expected Output

[
    {
        "Rating": 1,
        "SecondaryRatings": {
            "Primary": 1,
            "Price": 2,
            "Design": 4,
            "RatingDimension3": 1
        }
    },
    {
        "Rating": 7,
        "SecondaryRatings": {
            "Primary": 1,
            "Price": 2,
            "Design": 4,
            "RatingDimension3": 1
        }
    }
]

Actual Output

{
  "Rating" : [ 1, 7 ],
  "SecondaryRatings" : {
    "Price" : [ 2, 8 ],
    "Design" : [ 4, 9 ],
    "RatingDimension3" : [ 1, 10 ]
  }
}
question from:https://stackoverflow.com/questions/65911271/jolt-prefix-soup-example-with-an-array-of-objects-as-input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figured it out. Here is the spec in case anyone else needs it.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "rating-*": "[&1].SecondaryRatings.&(0,1)",
        "rating-primary": "[&1].Rating"
      }
    }
  }
]
'''

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...