Question
When attempting to add a label configuration through the Label Studio API, I receive an error even though the config works fine in the UI. What is the mistake in the following cURL command I’m using to add the label config via API?
!curl -X POST http://<omitted for security>:8080/api/projects/validate/ \
-H 'Authorization: Token <Omitted for security> ' \
-H 'Content-Type: application/json' \
-d '{"label_config": "<View><Header value="Listen to the audio:"/><Audio name="audio" value="$url"/><Text name="txt0" value="Is the word given below intelligible in the above audio ?"></Text><Text name="txt" value="$word"></Text><Text name="sentence" value="$text"></Text><Choices name="intelligibility" toName="audio" choice="single-radio" showInline="true"><Choice value="Yes"/><Choice value="No"/></Choices></View>"}'
Answer
The issue with the provided cURL command is due to JSON parsing errors arising from unescaped double quotes within the label_config
JSON property. To fix this, you need to use escaped double quotes (\"
) for HTML attribute values inside the JSON string or alternatively use single quotes ('
) for non-JSON strings. Here’s the corrected cURL command with the double quotes escaped:
shell
curl -X POST http://<omitted for security>:8080/api/projects/validate/ \
-H 'Authorization: Token <omitted for security>' \
-H 'Content-Type: application/json' \
-d '{"label_config": "<View><Header value=\"Listen to the audio:\"/><Audio name=\"audio\" value=\"$url\"/><Text name=\"txt0\" value=\"Is the word given below intelligible in the above audio ?\"></Text><Text name=\"txt\" value=\"$word\"></Text><Text name=\"sentence\" value=\"$text\"></Text><Choices name=\"intelligibility\" toName=\"audio\" choice=\"single-radio\" showInline=\"true\"><Choice value=\"Yes\"/><Choice value=\"No\"/></Choices></View>"}'
Ensure all the double quotes around HTML attributes in the label_config
value are properly escaped.