Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is json mapping in jolt json

Shulou Source: shulou.com Published: 2022-06-02 02:25:10 09月25日 Update

What is json mapping in jolt json? in view of this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Demo interpretation

With the foundation of the first article, operating jolt is no longer a problem, and most json mapping is already handy. This film mainly focuses on other functions of jolt in addition to json's mapping function.

The meaning of the pattern

Modify-default-beta modification-the default is to convert when the left-hand side does not exist or is empty.

Modify-overwrite-beta modification-overwrite retains the old data, and will be updated if the value is the same

Array (Array) correlation-List Functions

Json input

{"scores": [4,2,8,7,5]}

Json spec

[{"operation": "modify-overwrite-beta", "spec": {/ / calculate the length of the array "numScores": "= size (@ (1 score))", / / take the head and tail of the array "firstScore": "= firstElement (@ (1 score))", "lastScore": "= lastElement (@ (1 score))" / / unable to get the value "scoreAtMidPoint": "= elementAt (@ (1rem scores), 2)", / / sort the array "sortedScores": "= sort (@ (1m scores))"}}]

Json output

{"scores": [4,2,8,7,5], "numScores": 5, "firstScore": 4, "lastScore": 5, "sortedScores": [2,4,5,7,8]} Mathematical (Math) correlation-Math Functions

Json input

{"intData": [2,7,5], "doubleData": [0.25,1.5,1], "a": 10, "b": 5, "c": 3, "negative": "- 1.0"}

Json spec

[{"operation": "modify-overwrite-beta", "spec": {/ / array summation "sumIntData": "= intSum (@ (1mint intData))", "sumLongData": "= intSum (@ (1mint intData))", / / same as intSum The difference is that it returns Java Long "sumDoubleData": "= doubleSum (@ (1MagneData))", / / the array finds the average "avgIntData": "= avg (@ (1PowerintData))", / / returns the double type "avgDoubleData": "= avg (@ (1MaginintData))", / / the array sort "sortedIntScores": "= sort (@ (1quotation intData))" / / get the minimum value "minAB": "= min (@ (1Powera), @ (1Powerb))", / / get the maximum value "maxAB": "= max (@ (1Powera), @ (1pencil b))", / / get the absolute value "abs": "= abs (@ (1pencil negative))" / / Division "aDivB": "= divide (@ (1Powera), @ (1recoverb))", "aDivC": "= divide (@ (1Powera), @ (1Menc))", / Division rounded "aDivCRounded4": "= divideAndRound (4jue @ (1jue a), @ (1jue c)"}]

Json output

{"intData": [2,7,5], "doubleData": [0.25,1.5,1], "a": 10, "b": 5, "c": 3, "negative": "- 1.0"," sumIntData ": 14," sumLongData ": 14," sumDoubleData ": 2.75," avgIntData": 4.666666666666667, "avgDoubleData": 0.9166666666666666, "sortedIntScores": [2,5 " 7], "minAB": 5, "maxAB": 10, "abs": 1.0, "aDivB": 2.0, "aDivC": 3.3333333333333335, "aDivCRounded4": 3.3333} Type conversion-Type Conversion

Json input

{"happy": "true", "meh": "meh", "answer": 42, "statistics": [{"id": "A", "min": "2.0", "max": "10.0", "avg": "7.9"}, {"min": "6", "max": "6" "avg": "6"}, {"id": "C"}]}

Json spec

[{"operation": "modify-overwrite-beta", "spec": {/ / string to Boolean "happy": "= toBoolean", / / if it is not Boolean You can set false "meh" to boolean: ["= toBoolean", false], / convert numbers to string "answer": "= toString", / / do some type conversion exercises below Default data to default "statistics": {"*": {/ / convert integer default setting 0 "min": ["= toInteger", 0], / / convert integer default setting null "max": ["= toInteger", null] / / convert to floating point default setting null "avg": ["= toDouble", null], / / id column defaults to set UNKNOWN "_ id": "UNKNOWN"}]

Json output

{"happy": true, "meh": false, "answer": "42", "statistics": [{"id": "A", "min": 2, "max": 10, "avg": 7.9}, {"min": 6, "max": 6, "avg": 6.0, "id": "UNKNOWN"} {"id": "C", "min": 0, "max": null, "avg": null}]} string concatenation-String Concatenation

Json input

{"x": [3,2,1, "go"], "small": "small", "BIG": "BIG", "people": [{"firstName": "Bob", "lastName": "Smith", "address": {"state": null}}, {"firstName": "Sterling" "lastName": "Archer"}]}

Json spec

[{/ / modify-default-beta pattern means to convert when the left-hand side does not exist or is empty. "operation": "modify-default-beta", "spec": {/ / @ (1scorex) parses the elements in the x array Then combine / / y combine the elements in the x array through commas / / z through join and combine the elements in the x array through spaces through join "y": "= join (',', @ (1dhorex))", "z": "= join ('', @ (1jinx))" / all uppercase or lowercase English characters are converted to "small_toUpper": "= toUpper (@ (1jinsmall)", "BIG_toLower": "= toLower (@ (1jinbig))", "people": {"*": {/ / 1 means Drill into the second layer of data "fullName": "= concat (@ (1jinfirstName),'', @ (1MagneLastName)), / / suffix hello means that" address? ": {" state ":" Texas "}} will be parsed only when there is an address field.]

Json output

{"x": [3,2,1, "go"], "small": "small", "BIG": "BIG", "people": [{"firstName": "Bob", "lastName": "Smith", "address": {"state": "Texas"}, "fullName": "Bob Smith"}, {"firstName": "Sterling" "lastName": "Archer", "fullName": "Sterling Archer"}], "y": "3Power2 go 1jiggo", "z": "321 go", "small_toUpper": "SMALL", "BIG_toLower": "big"} this is the answer to the question about what json mapping is in jolt json. I hope the above content can help you to a certain extent, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.

Tags: Array character question element string data type combination function meaning left hand Boolean time more pattern division help sort solution different Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Linux vpn Redmi