0

Hello after i successfully parsed my metadata into an excel im now at the challenge to parse it back to an Cardano Blockchain compatible Metadata.JSON

but unfortunatly im not able to fit the right metadata structur

Thats what it should be:

 {
  "721": {
    "policy": {
      "tokenname": {
        "country": "1",
        "test": "123"
      },
      "tokenname": {
        "country": "1",
        "test": "123"
      }
    }
  }
}

thats my current status: my code and result

Sub live_json()
Dim rng As Range, items As New Collection, myitem As New Dictionary, subitem As New Dictionary, i As Integer, cell As Variant
'Set rng = Range("A2:A3")
'Set rng = Range(Sheets(2).Range("A2"), Sheets(2).Range("A2").End(xlDown)) use this for dynamic range

   Set abc = New Collection
    abc.Add ("721")
    
For a = 0 To 2
    subitem("country") = "123"
    subitem("test") = "123"
    myitem.Add "tokenname", subitem
    items.Add myitem
    Set myitem = Nothing
    Set subitem = Nothing
Next

    abc.Add items

MsgBox (ConvertToJson(abc, Whitespace:=2))
End Sub

I think im nearly there

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

This worked for me:

Sub live_json()
    
    Dim root As Dictionary, k As Dictionary, a As Long

    Set root = New Dictionary
    Set k = New Dictionary
   
    root.Add "721", k
    k.Add "policy", New Dictionary
    Set k = k("policy")
   
    For a = 0 To 2
        k.Add "tokenname" & a, New Dictionary
        With k("tokenname" & a)
            .Add "country", "1"
            .Add "test", "123"
        End With
    Next

    Debug.Print ConvertToJson(root, Whitespace:=2)
End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Thank you very much excatly whats needed! Now i can start uploading metadata to the cardano blockchain via an vba macro :) ! – Patrick Pedronetto Dec 16 '21 at 00:33
  • do we have the possiblity to add subitems with? i tried a lot but do i have to add a Collection or a Dictionary to k? { "721": { "policy": { "tokenname": { "country": "1", "test": "123", "properties": [ { "key": "blue", "value": "human" } ], "links": [ { "link1": "www", "link2": "www2" } ], }, "tokenname": { – Patrick Pedronetto Dec 22 '21 at 14:36
  • You can update your question to add that - not really readable in a comment. Basically for `[...]` you'd add a collection, and for `{...}` you'd add a dictionary. – Tim Williams Dec 22 '21 at 16:49
  • You really need to ask a new question, or at least update your question above, not my answer. – Tim Williams Dec 23 '21 at 21:53
  • sorry im pretty new to this space. – Patrick Pedronetto Dec 24 '21 at 02:52