有没有办法根据键来映射它?
有没有办法根据键(“A”、“A-BOMB”等)映射下面的 JSON 示例?基本上我希望客户输入他们想要定义的单词,然后将其存储在变量中。假设他们要查找的单词存储在 vars.word 中,有没有一种方法可以映射 dataweave,以便它可以找到它并返回任何同义词、含义、同义词等?
{
"A": {
"ANTONYMS": [],
"MEANINGS": {
"6": [
"Noun",
"the 1st letter of the Roman alphabet",
[
"Letter",
"Letter of the alphabet",
"Alphabetic character"
],
[]
],
"7": [
"Noun",
"the blood group whose red cells carry the A antigen",
[
"Blood group",
"Blood type"
],
[]
]
},
"SYNONYMS": [
"Ampere",
"Type a",
"Antiophthalmic factor",
"Angstrom",
"Adenine"
]
},
"A-BOMB": {
"ANTONYMS": [],
"MEANINGS": {},
"SYNONYMS": [
"Atomic bomb",
"Fission bomb",
"Plutonium bomb",
"Atom bomb",
"A-bomb"
]
},
"A-HORIZON": {
"ANTONYMS": [],
"MEANINGS": {
"1": [
"Noun",
"the top layer of a soil profile; usually contains humus",
[],
[]
]
},
"SYNONYMS": [
"A-horizon",
"A horizon"
]
}
我已经
尝试过 filterObject ((value, key) -> valuestartsWith vars.word)
不确定是否应该使用过滤器、查找或startsWith函数。我不知道我在做什么。这甚至可能是不可能的。我只是不知道从哪里开始
Is there a way to map the below JSON example based on the keys ("A", "A-BOMB" etc)? Basically i want the client to input a word they want a definition for, and i store that in a variable. So lets say the word they're looking for is stored in vars.word, is there a way to map the dataweave so that it can find it and return the anyonyms, meaning, synonyms etc?
{
"A": {
"ANTONYMS": [],
"MEANINGS": {
"6": [
"Noun",
"the 1st letter of the Roman alphabet",
[
"Letter",
"Letter of the alphabet",
"Alphabetic character"
],
[]
],
"7": [
"Noun",
"the blood group whose red cells carry the A antigen",
[
"Blood group",
"Blood type"
],
[]
]
},
"SYNONYMS": [
"Ampere",
"Type a",
"Antiophthalmic factor",
"Angstrom",
"Adenine"
]
},
"A-BOMB": {
"ANTONYMS": [],
"MEANINGS": {},
"SYNONYMS": [
"Atomic bomb",
"Fission bomb",
"Plutonium bomb",
"Atom bomb",
"A-bomb"
]
},
"A-HORIZON": {
"ANTONYMS": [],
"MEANINGS": {
"1": [
"Noun",
"the top layer of a soil profile; usually contains humus",
[],
[]
]
},
"SYNONYMS": [
"A-horizon",
"A horizon"
]
}
}
I've tried filterObject ((value, key) -> value startsWith vars.word)
Not sure if i should use the filter, lookup or startsWith functions. I have no idea what I'm doing. It might not even be possible. I just don't even know where to start
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意->
startsWith
或contains
不适合这里,因为您的对象具有以 A 开头的所有键,并且您的要求是匹配整个单词。我认为使用仅数组/对象索引会对您有所帮助
DW
使用
filterObject
以及 匹配 会给你相同的结果DW
输出
Note->
startsWith
orcontains
wont fit here since your Object has all the keys starting with A and your requirement is to match the entire word.I think using Just Array/Object indexing would help you here
DW
Alternative approach using
filterObject
along with matches would give you same resultDW
Output