Hi,

In earlier versions of ballerina following should work for string to json
and json to string conversions.

import ballerina.lang.system;
import ballerina.lang.jsons;

function main(string[] args) {
    string s1 = "{'ab':'ddd'}";
    json jsonVal = s1;
    system:println(jsonVal);
    string s2 = jsons:toString(jsonVal);
    system:println(s2);
}

Thanks,

Anupama



On Mon, Oct 30, 2017 at 5:07 PM, Gayan Chamara <[email protected]> wrote:

> Hi Rajith & Suthagar,
> I tried the suggested method, but no luck. It gives the following error
> message,
>
> *incompatible types: 'string' cannot be converted to 'json'*
>
>
> I'm restricted to ballerina 0.89 because API Manager has not moved to a
> newer version yet.
>
> Regards,
> Gayan.
>
> On Mon, Oct 30, 2017 at 4:57 PM, Suthagar Kailayapathy <[email protected]>
> wrote:
>
>> Hi Gayan,
>>
>> Can you please take a look at here(last one),
>> https://groups.google.com/forum/#!topic/ballerina-dev/DIWQIULUvSw
>>
>> string s = "somejson";
>> json j;
>> Error e;
>> j, err = <json> s;
>>
>> Thanks.
>>
>> On Mon, Oct 30, 2017 at 4:39 PM, Gayan Chamara <[email protected]> wrote:
>>
>>> Hi,
>>> Is there a way to convert JSON string into ballerina json type in
>>> ballerina 0.89? I couldn't find a suitable method in the docs.
>>>
>>> Thanks,
>>> Gayan.
>>>
>>> --
>>> Regards,
>>>
>>> *Gayan Chamara*
>>>
>>> *Software Engineering Intern*
>>> *WSO2 Inc.*
>>>
>>>
>>> *Email: [email protected] <[email protected]> *
>>> *Mobile : **+94 71 728 5827 <+94%2071%20728%205827>*
>>> <http://wso2.com/signature>
>>>
>>
>>
>>
>> --
>>
>> *K.Suthagar*
>> Software Engineering Intern | WSO2
>> LinkedIn: https://www.linkedin.com/in/ksuthagar
>> <http://suthagar.inncaps.com/>
>>
>> Email: [email protected]
>> Mobile : +94779543968 <+94%2077%20954%203968>
>> Web: http://wso2.com
>>
>>
>
>
> --
> Regards,
>
> *Gayan Chamara*
>
> *Software Engineering Intern*
> *WSO2 Inc.*
>
>
> *Email: [email protected] <[email protected]> *
> *Mobile : **+94 71 728 5827 <+94%2071%20728%205827>*
> <http://wso2.com/signature>
>



-- 
Anupama Pathirage
Technical Lead
WSO2, Inc.  http://wso2.com/
Email: [email protected]
Blog: http://mycodeideas.blogspot.com
Mobile:+94 71 8273 979
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to