Skip to main content
New Participant
Jan 20, 2025 6:59 AM UTC
Question

Remove Square brackets [] from a string of output from a!tojson

I was sending a data in json format like { a!tojson("fruit": "apple") } but the output i was getting { "fruit": ["apple"] }but i need without square brackets . Could anyone please help me on this and thanks for advance

9 replies

nilanshum856600
Participating Frequently
Jan 20, 2025 7:21 AM UTC

To extract this value from JSON, first you need to parse the JSON using a!fromJson() to convert it into a dictionary. After that you can access the specific key to retrieve the value.

New Participant
Jan 20, 2025 9:22 AM UTC

i need it inside the a!tojson function

nilanshum856600
Participating Frequently
Jan 20, 2025 9:54 AM UTC

I didn't get your point. From what I understood, you had a JSON input and you wanted to extract a value from it. Then why would you use a!toJson() ?

stefanhelzle0001
Brainy
Jan 20, 2025 7:54 AM UTC

You could also use the extract() function.

extract("[""12hg""]", "[""", """]")

annap0005
Participating Frequently
Jan 20, 2025 2:31 PM UTC

Try this

a!localVariables( local!text: "[""12hg""]", stripwith( local!text,"["" ""]") )