json-lenses icon indicating copy to clipboard operation
json-lenses copied to clipboard

Extracting Seq of Seqs

Open conikeec opened this issue 10 years ago • 0 comments

Attempting to extract a Seq[Seq[String]] from this document

val json = JsonParser("""{
    "vmaz" : {
        "a" : {
            "b" : [ 
                {
                    "c" : {
                        "d" : [ 
                            {
                                "name" : "[Internal RAID10] 123",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 6443746134
                            }, 
                            {
                                "name" : "[Internal RAID10] 456",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 0
                            }, 
                            {
                                "name" : "[Internal RAID10] 789",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 25769803776
                            }, 
                            {
                                "name" : "[Internal RAID10] 111",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 0
                            }, 
                            {
                                "name" : "[Internal RAID10] 123",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 3615490048
                            }
                        ]
                    }
                }, 
                {
                    "c" : {
                        "d" : [ 
                            {
                                "name" : "11aa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 6443746148
                            }, 
                            {
                                "name" : "22aa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 0
                            }, 
                            {
                                "name" : "33aa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 1006686208
                            }, 
                            {
                                "name" : "44aa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 0
                            }, 
                            {
                                "name" : "55aa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 413696
                            }
                        ]
                    }
                }, 
                {
                    "c" : {
                        "d" : [ 
                            {
                                "name" : "66aaa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 6443746148
                            }, 
                            {
                                "name" : "77aaa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 0
                            }, 
                            {
                                "name" : "88aaaa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 15451869184
                            }, 
                            {
                                "name" : "999aaa",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 0
                            }, 
                            {
                                "name" : "10900assas",
                                "datastoreId" : "datastore-66",
                                "sizeInBytes" : 17190912
                            }
                        ]
                    }
                }
            ]
        }
    }
}""")

json.extract[Seq[Seq[String]]](fromPath("$.vm.a.b[*].c.d[*].name"))

I attempted other combinations and realized that it seems to be flattening it to a Seq[String]. I wouldn't want this but rather a Seq[Seq[String]] in order to preserve the alignment.

conikeec avatar Apr 08 '14 18:04 conikeec