www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - JSON decode?

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

from a rest call I get a JSON with a strange format:

{"DEPLOY_ATTRIBUTES":"{\n  \"dependency-type\": 
\"soft\"\n}","MTA_METADATA":"{\n  \"id\":...

The sub objects are enclosed with quotes and there are a lot of 
line break characters.
Also the quotes are escaped.
I try to translate a Python script which has no issues to handle 
this JSON correctly,
but I do not understand why.

Python seems to handle this with decode('utf-8')? Is there some 
functionality in Phobos to handle this format correctly?

Kind regards
André
Sep 27 2016
parent Andre Pany <andre s-e-a-p.de> writes:
On Tuesday, 27 September 2016 at 10:45:45 UTC, Andre Pany wrote:
 Hi,

 from a rest call I get a JSON with a strange format:

 {"DEPLOY_ATTRIBUTES":"{\n  \"dependency-type\": 
 \"soft\"\n}","MTA_METADATA":"{\n  \"id\":...

 The sub objects are enclosed with quotes and there are a lot of 
 line break characters.
 Also the quotes are escaped.
 I try to translate a Python script which has no issues to 
 handle this JSON correctly,
 but I do not understand why.

 Python seems to handle this with decode('utf-8')? Is there some 
 functionality in Phobos to handle this format correctly?

 Kind regards
 André
OK, I found the solution. There is no magic in python. For these kinds of attributes the python code checks whether it is a string, and then tries to parse again as JSON, wired! Kind regards André
Sep 27 2016