Skip to main content

I have a json object that contains nested arrays, a simplified example is:

{
   "Attr1" :  {
      "Attr2" : >{
         "Attr3" : "A"
 }
        ]
      }, {
      "Attr2" :  {
 "Attr3" : "B"
 }, {
 "Attr3" : "C"
 }
]
      }, {
      "Attr2" : 3{
         "Attr3" : "D"
 }, {
 "Attr3" : "E"
 }, {
 "Attr3" : "F"
 }
]
      }
     ]
}

I would like to extract just attr3, either as a (complex) list, or a valid json ex.  {"Attr3":"A"},{"Attr3":"B"},{"Attr3":"C"},{"Attr3":"D"},{"Attr3":"E"},{"Attr3":"F"}]

 

 

If I use the JSONExtractor with json3"Attr1"]
  • t"Attr2"]
  • I get {"Attr3":"A"}{"Attr3":"B"}{"Attr3":"C"}{"Attr3":"D"}{"Attr3":"E"}{"Attr3":"F"}'

    without commas between elments.

     

     

    The JSONFlattener with recursion does work, but the actual json has a couple of hundred additional elements, and I would like to avoid creating them unnecessarily if possible.
  • Hi @jdh

    I used JSONFragmenter with json["Attr1"]

  • ["Attr2"]
  • ["Attr3"]

    This yields 6 records with _result = 'A', _result = 'B', etc

    Then to make a list I used a ListBuilder which generated `_list{}._result' = {A,B,C,D,E,F}

    See attached: json2list.fmw

    Dean


  • Hi @jdh, I would use the StringReplacer to replace }{ with },{ after extracting the elements by the JSONExtractor.

    [Addition] An example: json-to-list.fmw or json-to-list-2.fmw


    Hi @jdh

    I used JSONFragmenter with json["Attr1"]

  • ["Attr2"]
  • ["Attr3"]

    This yields 6 records with _result = 'A', _result = 'B', etc

    Then to make a list I used a ListBuilder which generated `_list{}._result' = {A,B,C,D,E,F}

    See attached: json2list.fmw

    Dean

  • I thought of that, but I really want to avoid using blocking transformers for performance reasons.


    Hi @jdh, I would use the StringReplacer to replace }{ with },{ after extracting the elements by the JSONExtractor.

    [Addition] An example: json-to-list.fmw or json-to-list-2.fmw

    I've never tried the @ReplaceString in the text editor. I'll have to remember that in the future.


    No need for it to be blocking if you have a feature id to group by in the ListBuilder. If not you can make one with a Counter


    Reply