Skip to content

[ 2374913 ] How to handle masked backslashes? #407

@HolQue

Description

@HolQue

The following Python script defines JSON content and uses the standard JSON interface and the JsonPreprocessor to parse the JSON content and print the result:

json_data = '{"keyname": "value"}'

parsed_data_standard = json.loads(json_data)
print(parsed_data_standard)

oJsonPreprocessor = CJsonPreprocessor()
parsed_data_jpp = oJsonPreprocessor.jsonLoads(json_data)
print(parsed_data_jpp)

Outcome:

{'keyname': 'value'}
DotDict({'keyname': 'value'})

This is like expected.

Now I change the JSON content to

json_data = '{"key\\name": "value"}'

Outcome:

{'key\name': 'value'}
Exception: Invalid key name: "key
ame". Key names have to start with a letter, digit or underscore.

The standard JSON interface works like expected, the masking of the backslash is resolved. But in the JsonPreprocessor results the '\n' is still an active escape sequence.

And the error message is wrong, because the key name is not invalid and also does not start with a forbidden character.

Now I read this content from file:

"key\\name": "value"

Result:

DotDict({'key\\name': 'value'})

I am not sure if this is like expected, because this deviates from the output {'key\name': 'value'} of the standard JSON interface. My understanding is that in Python - after parsing with JSON interface - all escape sequences are resolved internally. Therefore the name of the key should be "key\name".

Is it possible to use such a key name?

I tried:

"param\\1" : "value",
"param_2"  : ${param\\1}

Outcome:

Error: 'The parameter '${param\1}' is not available!'!

But intuitively I would expect that it's possible to implement in this way.

It seems to me that the internal computation of escape sequences needs to be reworked and aligned.

Maybe related to: #356

Metadata

Metadata

Assignees

Projects

Status

Open

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions