molsonkiko / JsonToolsNppPlugin

A Notepad++ plugin providing tools for JSON like linting, querying, a tree view, and CSV conversion.
Apache License 2.0
70 stars 9 forks source link

JSON to YAML: wrong escaping of strings beginning with # #63

Closed bartoszjklimek closed 2 months ago

bartoszjklimek commented 2 months ago

I'm trying to convert a JSON schema file to a YAML file. Unfortunately strings beginning with # are not quoted and therefore interpreted as comments. E.g. for such JSON fragment:

       "node": {
            "type": "object",
            "properties": {
                "Value": {
                    "type": "string"
                },
                "creationTimestamp": {
                    "$ref": "#/$defs/typeLongDate"
                }
            }

the following YAML fragment is generated:

    node:
        type: object
        properties:
            Value:
                type: string
            creationTimestamp:
                $ref: #/$defs/typeLongDate

The expected result would be:

    node:
        type: object
        properties:
            Value:
                type: string
            creationTimestamp:
                $ref: '#/$defs/typeLongDate'

I'm using Notepad++ v8.6.5 and JSON Tools 7.1.

molsonkiko commented 2 months ago

@bartoszjklimek Thanks for letting me know about this issue.

Unfortunately, I concluded a long time ago that converting JSON to YAML is really difficult, and that therefore handling every corner case is beyond the scope of JsonTools. That is why, whenever someone uses that plugin command, I have the message box warning the user that the conversion may not work as intended.

I'm not going to fix this issue, because correctly handling every corner case would probably require several thousand lines of code and there are plenty of other ways to convert JSON to YAML. If you would like, I can add a unit test so that most recent errors.txt reflects the fact that JsonTools breaks in this case.

As noted in the docs, a good way to convert YAML to JSON would be to use PyYAML