-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate array always for specified xml element #2514
Comments
Hi, seems unrelated to jq. Did you mean to open an issue for https://github.com/kislyuk/yq, https://github.com/mikefarah/yq or https://github.com/wader/fq etc? but maybe you can post-process the JSON, something like {
"root": [
{
"aitem": [
{
"name": "abc",
"value": "123"
}
],
"bitem": [
{
"name": "bbbb",
"value": "2222"
},
{
"name": "BB",
"value": "22"
}
]
}
]
} |
@wader ,Thanks for your attention yes i tried converting xml to json with yq first, helpful if you can provide solution for same within YQ I am trying to process with JQ for proper json Can we do xml>json conversion & serialize json with FQ , Do any of the YQ, JQ, FQ packages do conversion & serialize output based on XML or JSON schema Please correct my command or how can i use same in definition file
|
Not sure about yq, and not sure which one of the two named yq your using. But with fq you can do: $ fq 'walk(if type == "object" then with_entries(.value |= if type == "object" then [.] end) end)' test.xml
{
"root": [
{
"aitem": [
{
"name": "abc",
"value": "123"
}
],
"bitem": [
{
"name": "bbbb",
"value": "2222"
},
{
"name": "BB",
"value": "22"
}
]
}
]
}
# and you can manipulate the json and get xml back as the values follow the xml<->json mapping rules
$ fq -r '.root.bitem += [{hello: 123}] | to_xml({indent:2})' test.xml
<root>
<aitem>
<name>abc</name>
<value>123</value>
</aitem>
<bitem>
<name>bbbb</name>
<value>2222</value>
</bitem>
<bitem>
<name>BB</name>
<value>22</value>
</bitem>
<bitem>
<hello>123</hello>
</bitem>
</root> |
Working with FQ now, Any idea can i create xsd schema files & ask FQ to do accordingly as per schema file. Requirement as below , would need two tasks doing in single command
|
fq does not currently support decoding to json based on xsd, don't know if one of the yq:s does. It's not something i plan on adding myself at the moment, but feel free to work on it. |
Normal Output aitem{} bitem[{}{}]
Expected Output , aitem[{}] bitem[{}{}] even its single set aitem must become array
The text was updated successfully, but these errors were encountered: