Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Convert XML from clipboard or current document/selection to JSON functionality in VSCode.

License

NotificationsYou must be signed in to change notification settings

anhthang/vscode-xml2json

Repository files navigation

Convert XML from clipboard or current document/selection to JSON

VersionInstallsDownloadsRating

Are you usingCode and working with XML builder tools day by day?

XML to JSON can help you create the final object, just edit the variables that need dynamic data instead of typing each object key, attribute and no typos mistake. Converted data can be use forxmlbuilder,xml2js or your expected format using configuration options.

Here are just some of the features that XML to JSON provides:

  • Convert XML from document or selection to JSON
  • Convert XML from clipboard to JSON

📝 Changelog

See therelease notes for the full set of changes

🏙 Preview

png

🔧 Configuration

By default, it's followingxml2js default options. If you wanna change, choose one of pre-defined options (eg:xmlbuilder) or selectcustom and edit insettings.json. Below is an example:

{"xml2json.defaultSettings":"custom","xml2json.options": {"attrkey":"@","explicitArray":false,"mergeAttrs":true    }}

Availablie options:

Followingxml2js

NameDefaultDescription
attrkey$Prefix that is used to access the attributes. Version 0.1 default was @.
charkey_Prefix that is used to access the character content. Version 0.1 default was #.
explicitCharkeyfalse
trimfalseTrim the whitespace at the beginning and end of text nodes.
normalizeTagsfalseNormalize all tag names to lowercase.
normalizefalseTrim whitespaces inside text nodes.
explicitRoottrueSet this if you want to get the root node in the resulting object.
emptyTagwhat will the value of empty nodes be.
explicitArraytrueAlways put child nodes in an array if true; otherwise an array is created only if there is more than one.
ignoreAttrsfalseIgnore all XML attributes and only create text nodes.
mergeAttrsfalseMerge attributes and child elements as properties of the parent, instead of keying attributes off a child attribute object. This option is ignored if ignoreAttrs is false.
validatornullYou can specify a callable that validates the resulting structure somehow, however you want. See unit tests for an example.
xmlnsfalseGive each element a field usually called '$ns' (the first character is the same as attrkey) that contains its local name and namespace URI.
explicitChildrenfalsePut child elements to separate property. Doesn't work with mergeAttrs = true. If element has no children then children won't be created. Added in 0.2.5.
childkey$$Prefix that is used to access child elements if explicitChildren is set to true. Added in 0.2.5.
preserveChildrenOrderfalseModifies the behavior of explicitChildren so that the value of the children property becomes an ordered array. When this is true, every node will also get a #name field whose value will correspond to the XML nodeName, so that you may iterate the children array and still be able to determine node names. The named (and potentially unordered) properties are also retained in this configuration at the same level as the ordered children array. Added in 0.4.9.
charsAsChildrenfalseDetermines whether chars should be considered children if explicitChildren is on. Added in 0.2.5.
includeWhiteCharsfalseDetermines whether whitespace-only text nodes should be included. Added in 0.4.17.
asyncfalseShould the callbacks be async? This might be an incompatible change if your code depends on sync execution of callbacks. Future versions of xml2js might change this default, so the recommendation is to not depend on sync execution anyway. Added in 0.2.6.
stricttrueSet sax-js to strict or non-strict parsing mode. Defaults to true which is highly recommended, since parsing HTML which is not well-formed XML might yield just about anything. Added in 0.2.7.
attrNameProcessors(*)nullAllows the addition of attribute name processing functions. Accepts an Array of functions. Added in 0.4.14.
attrValueProcessors(*)nullAllows the addition of attribute value processing functions. Accepts an Array of functions. Added in 0.4.1.
tagNameProcessors(*)nullAllows the addition of tag name processing functions. Accepts an Array of functions. Added in 0.4.1.
valueProcessors(*)nullAllows the addition of element value processing functions. Accepts an Array of functions. Added in 0.4.6.

Note

(*): These configuration is not supported this time due to Code extension only supportarray,boolean,integer,null,number,object,string.

📸 Screenshots

pngpng

📝 Icon Credit

XML, JSON file icon bySmashicons fromFlaticon -Flaticon Basic License

About

Convert XML from clipboard or current document/selection to JSON functionality in VSCode.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp