Forum Discussion

smpa01's avatar
smpa01
Icon for Community Champion rankCommunity Champion
1 year ago

json indenting

Is it at all possible to indent a measure with json structure

 

 

// what I need the mesure to output
{
    "companyName": "Tech Innovators Inc.",
    "location": "San Francisco",
    "departments": [
        {
            "name": "Engineering",
            "manager": {
                "name": "Alice Johnson",
                "email": "[email protected]"
            },
            "employees": [
                {
                    "name": "Bob Smith",
                    "role": "Software Engineer",
                    "email": "[email protected]"
                },
                {
                    "name": "Charlie Evans",
                    "role": "DevOps Engineer",
                    "email": "[email protected]"
                }
            ]
        },
        {
            "name": "Marketing",
            "manager": {
                "name": "Diana Brown",
                "email": "[email protected]"
            },
            "employees": [
                {
                    "name": "Eve Turner",
                    "role": "Marketing Specialist",
                    "email": "[email protected]"
                },
                {
                    "name": "Franklin Harris",
                    "role": "Content Writer",
                    "email": "[email protected]"
                }
            ]
        },
        {
            "name": "Sales",
            "manager": {
                "name": "George Wilson",
                "email": "[email protected]"
            },
            "employees": [
                {
                    "name": "Hannah Lee",
                    "role": "Account Manager",
                    "email": "[email protected]"
                },
                {
                    "name": "Ian Thomas",
                    "role": "Sales Executive",
                    "email": "[email protected]"
                }
            ]
        }
    ],
    "financials": {
        "revenue": 5000000,
        "expenses": 2000000,
        "netProfit": 3000000
    }
}

 

 

what I am getting

sample dataset

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lVNLT/MwEPwrVs4IIRAXTrz68RAvKZU4ND1szTZZ4exGthtAqP+djUurNv2KIKdodzwzO16PRtlnkVmpG+CPB6ixyE6KbIi2MjfM0kIUH/TX7hfZXpE5sRBJOKFyYPPPA1sKVlL7BRvwsUaOQREjZeYl5YBLYkRPXCZoDQwleu2to84cWTS3UnHoRBSHNZBLPeh6p1Gt0crZvjovsnnCNU4+ELeEz2Vi8ppilei8uEU5l2l8A49maaynNpHJDq118osKvCMlaYHDpsAlto9N2EVvFwf/LzHeFLkH/4rx5+AuScvm3MtbP7aXrvP32AYtmuHM87fz1VgrMyZv0JJeSog9RWx3XdO6QLc5r47YXIP31AvvQjjqFplnT3Eru+n3yV+Fl4PD8ENwVyi+RPNMbnvjytT7e3bXwAyVuUPcnOrMWpnpVPdLJxtqVTr1i+Ru9N0NK6mhF1oa1Qze0c4itdij1zXYFdhYgVPi7iWDC4uAvN4izzri44P0dWTvDXJI8x6uiozxycuUdAtOjhbV+Twbj78A", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}})
in
    #"Changed Type"

 

 

AlexisOlson 

 

Thank  you in advance

5 Replies

  • What's the purpose of the indenting? The json itself doesn't care as long as the syntax is correct.

    • smpa01's avatar
      smpa01
      Icon for Community Champion rankCommunity Champion

      Sorry, If I understand correctly, Are you suggesting that if the pq recives an indented json from source, it is able to deliver it as is through the measure?

  • You want a DAX measure to auto-format a JSON string? I think you might be able to get close but it would be a hack job.

     

    What's the ultimate purpose?

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    the data recives a column which has json. I need to show the end user the column content through a dax measure  properly indented way cause with the current structure, there is no way for any1 to make sense from the totally scramabled measure.

     

    I was wondering if there is any native dax support for this, since there is TOJSON avaiable but there is no indenting avaiable. Worst case, needs to be delivered through a cust viz. For such a small thing, I would hate creating a cust viz.

     

    This is ugly