Skip to content
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

XML to JSON Conversion Issue #707

Open
gauravs456 opened this issue Jun 26, 2024 · 3 comments
Open

XML to JSON Conversion Issue #707

gauravs456 opened this issue Jun 26, 2024 · 3 comments

Comments

@gauravs456
Copy link

gauravs456 commented Jun 26, 2024

Hi Folks,
I am facing the issue while converting the xml to json
XML I have

<Response> <Audio>https://example.com/audio-files/12345/random-audio.mp3</Audio> <Connect trunk="Opensips-Incoming-ABC_1234567890" callerId="1234567890" webhookUrl="https://webhook.site/abcdefg-hijklmnop-qrstuv-wxyz" webhookMethod="POST" terminateOnHangup="true">+1234567890</Connect> <Audio>https://example.com/audio-files/67890/another-random-audio.mp3</Audio> </Response>

The output I am receiving is

{ "Response": { "Audio": [ "https://example.com/audio-files/12345/random-audio.mp3", "https://example.com/audio-files/67890/another-random-audio.mp3" ], "Connect": { "trunk": "Opensips-Incoming-ABC_1234567890", "callerId": "1234567890", "webhookUrl": "https://webhook.site/abcdefg-hijklmnop-qrstuv-wxyz", "webhookMethod": "POST", "terminateOnHangup": "true", "number": "+1234567890" } } }

and the Output I want in json is like

{ "Response": { "Audio": "https://example.com/audio-files/12345/random-audio.mp3", "Connect": { "trunk": "Opensips-Incoming-ABC_1234567890", "callerId": "1234567890", "webhookUrl": "https://webhook.site/abcdefg-hijklmnop-qrstuv-wxyz", "webhookMethod": "POST", "terminateOnHangup": "true", "number": "+1234567890" }, "Audio": "https://example.com/audio-files/67890/another-random-audio.mp3" } }
how can i acheive this using the library

@Leonidas-from-XIV
Copy link
Owner

Leonidas-from-XIV commented Jun 26, 2024 via email

@gauravs456
Copy link
Author

It is merging the same key in single error i want seperate object how can i achieve this

@Progressandfortuna
Copy link

I'd recommend building two separate xml2js parser files for API calls, as it's the solution which always works.

As of recent, you can nest multiple (2) objects in the parser without calling reset. This does require prior CDATA recognising $root as the primary object and changing the default settings, see docs from "mergeargs" to "async".

If you haven't fixed it yet, what's the full code you've inputted? As this is a linter issue, I also recommend looking into the eyes bug catcher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants