cancel
Showing results for 
Search instead for 
Did you mean: 

Transfer dollar sign as is in the Json request

SOLVED
Highlighted
Occasional Contributor

Transfer dollar sign as is in the Json request

Hi 

I have a JSON that contains in body "$" and I should transfer it By POST Rest request as is.


"value": "{\"container_procedures\":[{\"import\":{\"type\":\"LOAD\",\"json\":{\"file_path\":${PAPAYA_WORKING_DIR}\/quay.io.biocontainers.fastqc.0.11.8--1.tar\"}"

 

But this character is known as a dollar sign in the body of REST and  transferred as an empty value :

"value": "{\"container_procedures\":[{\"import\":{\"type\":\"LOAD\",\"json\":{\"file_path\":\"\/quay.io.biocontainers.fastqc.0.11.8--1.tar\"}

 

I tried with \$ but it doesn't help.

could you please advise how can I solve it?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Transfer dollar sign as is in the Json request

Hi @Rivka 

 

Ok - now I understand a little better - sorry - sometimes I don't read people's posts properly - so at the moment

{
"display": "TESTING",
"value": "${PAPAYA_WORKING_DIR}"
}

is being transformed to 

{
"display": "TESTING",
"value": ""
}

This is because ReadyAPI! is interpreting "${PAPAYA_WORKING_DIR}" as a parameter and I'm guessing it can't find what "${PAPAYA_WORKING_DIR}" represents - so it's blanking the value.

 

stick another $ sign in there - so it reads as follows:

 

{
"display": "TESTING",
"value": "$${PAPAYA_WORKING_DIR}"
}

this will generate 

{
"display": "TESTING",
"value": "${PAPAYA_WORKING_DIR}"
}

 

cool?

 

cheers,

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Re: Transfer dollar sign as is in the Json request

Hi @Rivka 

 

you've injecting escaped .json (which makes it a lot more difficult to read) rather than unescaped .json.

 

once the escaping is removed it reads as follows:

"value": "{"container_procedures":[{"import":{"type":"LOAD","json":{"file_path":${PAPAYA_WORKING_DIR}/quay.io.biocontainers.fastqc.0.11.8--1.tar"}"

which is malformed .json

 

you need to fix the .json so it's wellformed - then it will work properly.

 

There appear to be a number of issues making your .json malformed - no opening object/array opener, there is a single array opener but no closure for the array, and you're not closing any of the objects in there.

 

if you need to inject escaped .json rather than unescaped - don't forget to add the escaping once you've got your wellformed .json sorted!

 

Cheers,

 

richie

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Transfer dollar sign as is in the Json request

Hi @Rivka 

 

Ok - I tried fixing your .json and I've got it wellformed - but this is a guess - I don't know you're requirements - there could be arrays in there that I'm treating as objects - you need to confirm what the content is based on the requirements.

 

a wellformed example (not necessarily correct as I state above) is as follows:

{ "value":{ "container_procedures":{ "import":{ "type":"LOAD", "json":{ "file_path":"${PAPAYA_WORKING_DIR}/quay.io.biocontainers.fastqc.0.11.8--1.tar"} } } } }

I escaped the above string and it generated the following:

{ \"value\":{ \"container_procedures\":{ \"import\":{ \"type\":\"LOAD\", \"json\":{ \"file_path\":\"${PAPAYA_WORKING_DIR}\/quay.io.biocontainers.fastqc.0.11.8--1.tar\"} } } } }

As I say - the above isn't necessarily correct - I've just made some changes to make a wellformed esaped .json out of the malformed example you gave,

 

Hope this helps!

 

richie

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Transfer dollar sign as is in the Json request

Hi @richie 

I send you before only the problematic part of the JSON and not all content (please ignore about the form of JSON if you see anything related it )

This is the content of JSON

{
"display": "TESTING",
"description": "Run python tool",
"metadata": {

},
"inputs": ["imagename",
"in1",
"in2",
"in3",
"in4"],
"steps": [{
"reference": "Step/980",
"display": "run_jnj_qc_docker",
"arguments": [{
"executableId": "279",
"commandDisplay": "rundocker",
"parameterType": "PARAMETER",
"display": "payload",
"value": "{\"container_procedures\":[{\"import\":{\"type\":\"LOAD\",\"json\":{\"file_path\":\"${PAPAYA_WORKING_DIR}\/quay.io.biocontainers.fastqc.0.11.8--1.tar\"}},\"run\":{\"json\":{\"image\":\"quay.io/biocontainers/fastqc:0.11.8--1\",\"detach\":true,\"auto_remove\":false,\"command\":[\"fastqc\",\"-o\",\"analysis\",\"analysis\/%SEQUENCE%_L001_R1_001.fastq.gz\",\"analysis\/%SEQUENCE%_L001_R2_001.fastq.gz\",\"analysis\/%SEQUENCE%_L002_R1_001.fastq.gz\",\"analysis\/%SEQUENCE%_L002_R2_001.fastq.gz\"],\"volumes\":{\"\/scratch\/\":{\"bind\":\"\/references\",\"mode\":\"ro\"},\"${PAPAYA_WORKING_DIR}\/\":{\"bind\":\"\/analysis\",\"mode\":\"rw\"}},\"stdout\":true,\"stderr\":true}}}]}"
}]
}]
}

 

"value" field should contain text value only so you can see the JSON for this field with slashes.

 

Thanks

Rivka

Highlighted
Community Hero

Re: Transfer dollar sign as is in the Json request

Hi @Rivka 

 

The trouble is that the problem is most likely to be that the json is malformed.

 

I am using paramaters/properties in the payload of the tests I'm currently working on in ReadyAPI! - and it works fine and picks ups up the property/value correctly.

 

The easiest way to work out what the problem is (if it isn't malformed .json) is still to get the .json wellformed so json parsers can read the .json and help me analyse the json to assist in identifying the problem.

 

Hence the reason if at all possible to always provide the full payload (with security detail removed) when posting queries on the forum - it makes identifying the problem a lot easier - cos one issue can mask another.

 

Another way of looking at this is that ReadyAPI! has to read your .json to manipulate it/use it properly and so must use a .json parser.  HOWEVER - if the .json is malformed the parser can't read the .json and so ReadyAPI! won't do what you need it to do.  Before ReadyAPI! can do anything with your payload/message - ReadyAPI! needs to parse your message - so it makes sense to fix any malformed issues first - cos in this case, the malformed .json will definitely mask the issue - i.e. no replace your parameter with a property cos it can't read it.

 

I did check the latest .json you posted and it's still malformed.

 

if you want to prove that the issue is/isn't being masked by the malformed .json you could create a VIRT that responds to your request and just include something like the folllowing as the payload:

 

{
"file_path":"${PAPAYA_WORKING_DIR}/quay.io.biocontainers.fastqc.0.11.8--1.tar"
}

to prove that this successfully picks up the property you've parameterised?

 

cheers,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Occasional Contributor

Re: Transfer dollar sign as is in the Json request

Dear @richie 

I'm sorry maybe I was not clear with my question

I don't want to translate PAPAYA_WORKING_DIR to any value.

I don't want the function of dollar sign at all.

I want to pass it as a text '${PAPAYA_WORKING_DIR}'.(with dollar)

you can get the following Json as an example (hopefully is not malformed) :

{
"display": "TESTING",
"value": "${PAPAYA_WORKING_DIR}"
}

in ReadyAPI  it's translate to :

{
"display": "TESTING",
"value": ""
}

 

Note: 

I have not any a parameter PAPAYA_WORKING_DIR and it's should not be also.

I want to pass it as is in the request.:

{
"display": "TESTING",
"value": "${PAPAYA_WORKING_DIR}"
}

 I hope it's more clear now.

 

 

Highlighted
Community Hero

Re: Transfer dollar sign as is in the Json request

Hi @Rivka 

 

Ok - now I understand a little better - sorry - sometimes I don't read people's posts properly - so at the moment

{
"display": "TESTING",
"value": "${PAPAYA_WORKING_DIR}"
}

is being transformed to 

{
"display": "TESTING",
"value": ""
}

This is because ReadyAPI! is interpreting "${PAPAYA_WORKING_DIR}" as a parameter and I'm guessing it can't find what "${PAPAYA_WORKING_DIR}" represents - so it's blanking the value.

 

stick another $ sign in there - so it reads as follows:

 

{
"display": "TESTING",
"value": "$${PAPAYA_WORKING_DIR}"
}

this will generate 

{
"display": "TESTING",
"value": "${PAPAYA_WORKING_DIR}"
}

 

cool?

 

cheers,

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

Highlighted
Occasional Contributor

Re: Transfer dollar sign as is in the Json request

Hi @richie 

 

Very cool!!:Smiley Happy

it works.

 

Thank you very much

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors