Code Monkey home page Code Monkey logo

Comments (3)

SaraFarron avatar SaraFarron commented on August 11, 2024 1

Hm, I was thinking about json2xml replacing such characters with \" or &quote but on second thought you might be right that user should pass a valid json in the first place. Thanks for answering!

from json2xml.

vinitkumar avatar vinitkumar commented on August 11, 2024

Thanks for reporting the issue. I will look into it and try to implement a fix for it.

from json2xml.

vinitkumar avatar vinitkumar commented on August 11, 2024

@SaraFarron I think I know what's going wrong. I am confirm that nothing goes wrong if you JSON is a valid string.

    def test_dict_attr_crash(self):
        data = data = {
            "product": {
                "@attrs": {
                    "attr_name": "attr_value",
                    "a": "b"
                },
                "@val": [],
            },
        }
        result = json2xml.Json2xml(data).to_xml()
        dict_from_xml = xmltodict.parse(result)
        assert dict_from_xml["all"]["product"]["@attr_name"] == "attr_value"
        assert dict_from_xml["all"]["product"]["@a"] == "b"

I added your JSON into a test and it just seems to work.

The issue with your JSON string is that you are adding the attrs in a ' quote.

{
    "product": {
        "@attrs": {
            'attr_name': 'attr_value"'
        },
        "@val": [],
    },
}

If you fix that, the data is like this:

 {
    "product": {
        "@attrs": {
            "attr_name": "attr_value"
        },
        "@val": [],
    },
}

It would just work

from json2xml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.