C3 Data Convert Example

4

Index

Stats

2,710 visits, 5,752 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 27 Dec, 2023. Last updated 11 Sep, 2024

Array to JSON(Dictionary)

There is an array

ID		Name	Cost	Price
a001	Apple	12		3
a002	Banana	24		6
a003	Carrot	32		8
a004	Shroom	12		3

Array to JSON:as Dictionary

now You Want Convert Array to JSON. Use the Header as Dictionary Key.

{
    "a001": { "ID": "a001", "Name":"Apple", "Cost":12 },
    "a002": { "ID": "a002", "Name":"Banana", "Cost":24 },
    "a003": { "ID": "a003", "Name":"Carrot", "Cost":32 },
}

In this way, you can get item data through JSON

JSON.Get("a001.Name") // Apple

How to do it with eventsheet?

clipboard (need Object: Array, JSON)

{"is-c3-clipboard-data":true,"type":"events","items":[{"functionName":"ConvertArrayToJSON","functionDescription":"","functionCategory":"","functionReturnType":"none","functionCopyPicked":false,"functionIsAsync":false,"functionParameters":[],"eventType":"function-block","conditions":[],"actions":[],"children":[{"eventType":"block","conditions":[{"id":"for","objectClass":"System","parameters":{"name":"\"row\"","start-index":"1","end-index":"Array.Height-1"}}],"actions":[{"id":"set-path","objectClass":"JSON","parameters":{"path":"str(Array.At(0, loopindex))"}},{"id":"set-object","objectClass":"JSON","parameters":{"path":"Self.Path"}}],"children":[{"eventType":"block","conditions":[{"id":"for-each-element","objectClass":"Array","parameters":{"axes":"x"}}],"actions":[{"id":"set-value","objectClass":"JSON","parameters":{"path":"\".\" & str(Array.CurValue)","value":"Array.At(Array.CurX, loopindex(\"row\"))"}}]}]}]}]}
  • 0 Comments

Want to leave a comment? Login or Register an account!