Skip to content

Commit

Permalink
Rename bbes includes converting
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Sep 18, 2024
1 parent 9e6fed9 commit 4c9de50
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Casting immutable values will work. However, it does not do numeric conversions.
- [Open records](/learn/by-example/open-records/)
- [Control openness](/learn/by-example/controlling-openness/)
- [Anydata type](/learn/by-example/anydata-type/)
- [Converting from JSON to user defined type with langlib functions](/learn/by-example/converting-from-json-to-user-defined-type-with-langlib-functions/)
- [Convert from JSON to user defined type with langlib functions](/learn/by-example/convert-from-json-to-user-defined-type-with-langlib-functions/)
- [Check expression](/learn/by-example/check-expression/)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Converting from `table` and `xml` to JSON
# Convert from `table` and `xml` to JSON

`toJson()` recursively converts `anydata` to `json`. Table values are converted to `json` arrays and `xml` values are converted to strings.

::: code converting_from_table_and_xml_to_json.bal :::
::: code convert_from_table_and_xml_to_json.bal :::

::: out converting_from_table_and_xml_to_json.out :::
::: out convert_from_table_and_xml_to_json.out :::

## Related links
- [JSON type](/learn/by-example/json-type)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ bal run converting_from_table_and_xml_to_json.bal
$ bal run convert_from_table_and_xml_to_json.bal
true
[{"id":1,"name":"John"},{"id":2,"name":"Sam"}]
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Conversion of a `json` value to JSON format is straightforward. Converting from

In many cases, the conversion happens automatically when the user-defined type is a subtype of JSON as well as of `anydata`. With tables, XML or records that are open to `anydata` use `toJson()` to convert `anydata` to `json`. APIs that generate JSON typically accept `anydata` and automatically apply `toJson()`.

::: code converting_from_user_defined_type_to_json.bal :::
::: code convert_from_user_defined_type_to_json.bal :::

::: out converting_from_user_defined_type_to_json.out :::
::: out convert_from_user_defined_type_to_json.out :::

## Related links
- [JSON type](/learn/by-example/json-type/)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
$ bal run converting_from_user_defined_type_to_json.bal
$ bal run convert_from_user_defined_type_to_json.bal
{"name":"Colombo","cords":[6.95,79.84]}
{"name":"Colombo","cords":[6.94,79.83],"area":"03"}
4 changes: 2 additions & 2 deletions examples/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,14 @@
},
{
"name": "Convert from user-defined type to JSON",
"url": "converting-from-user-defined-type-to-json",
"url": "convert-from-user-defined-type-to-json",
"verifyBuild": true,
"verifyOutput": true,
"isLearnByExample": true
},
{
"name": "Convert from table and XML to JSON",
"url": "converting-from-table-and-xml-to-json",
"url": "convert-from-table-and-xml-to-json",
"verifyBuild": true,
"verifyOutput": true,
"isLearnByExample": true
Expand Down
2 changes: 1 addition & 1 deletion examples/json-numbers/json_numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Ballerina has three numeric types; but JSON has one. The `json` type allows `int

## Related links
- [Casting JSON to user-defined type](/learn/by-example/casting-json-to-user-defined-type/)
- [Converting to user-defined type](/learn/by-example/converting-to-user-defined-type/)
- [Convert to user-defined type](/learn/by-example/convert-to-user-defined-type/)
- [JSON type](/learn/by-example/json-type/)
2 changes: 1 addition & 1 deletion examples/json-type/json_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ The `json` type can be explained as a union of the simple basic types, `string`,
## Related links
- [Access JSON elements](/learn/by-example/access-json-elements/)
- [Convert from JSON to user-defined type](/learn/by-example/convert-from-json-to-user-defined-type/)
- [Convert from user-defined type to JSON](/learn/by-example/converting-from-user-defined-type-to-json/)
- [Convert from user-defined type to JSON](/learn/by-example/convert-from-user-defined-type-to-json/)
- [fromJsonString](https://lib.ballerina.io/ballerina/lang.value/0.0.0#fromJsonString)
- [cloneWithType](https://lib.ballerina.io/ballerina/lang.value/0.0.0#cloneWithType)

0 comments on commit 4c9de50

Please sign in to comment.