Forum Discussion

virender_prajap's avatar
virender_prajap
New Contributor III
7 years ago

How to split the string on the basis of length of bytes

How can i Split string( UTF-8) on the basis of bytes length and not on the basis of character counts.
e.g String > 4000 bytes then split the string into multiple columns each not more than 4000 bytes.
Like, if string1 ~ 10,000 bytes then, first 4000 bytes in column1, next 4000 bytes in column2 and so on…
If String < 4000, then in a single column.

5 Replies

  • HI Deepti - update the second Mapper expression to the following:

    $items
    .map(x=> x.merge(
    { "additionalCoding" : { "workOrderNumber" : $project.projectId } 
    ,  "contractDetails" : { "workOrderNumber" : $project.projectId } }
    )
    )
    

    So rather than an Object.extend(), we'll use Object.merge() to do a deep merge of the object, allowing us to also add the workOrderNumber into the existing contractDetails sub-element.

    Hope this gets you closer to your goal!

  • Deepti's avatar
    Deepti
    New Contributor II

    Hi bojanvelevski, I've read through a number of your insightful responses to other posts here, so I know you'll have something to offer me as well. Anticipating a response from you.TIA.

     

    Deepti

  • Deepti - can you simplify the input/desired output?  This is a lot to try to ingest and infer.  If you could remove any extraneous fields that don't help explain the actual logic required, that would be helpful for someone to come up with a solution.

  • Deepti's avatar
    Deepti
    New Contributor II

    Hi koryknick ,

    My bad, please find below a simplified version of same:

    Input:

    {
       "project": {
          "projectId": 2
       },
       "items": [
          {
             "description": "Architecture Fees",
             "unitPrice": "1000",
             "projectActivity": {
                "chartCodes": [
                   {
                      "chartCode": {
                         "uniqueCode": "7845",
                         "supplementalType": "BOMA"
                      }
                   }
                ]
             }
          },
          {
             "description": "02 Site Utilities",
             "unitPrice": "2000",
             "projectActivity": {
                "chartCodes": []
             }
          }
       ]
    }

    Desired output:

    {
       "order": {
          "orderLineItems": {
             "orderLineItem": [
                {
                   "lineItemName": "Architecture Fees",
                   "unitCost": "1000",
                   "contractDetails": {
                      "activity": "20_7845_9999"
                   },
                   "additionalCoding": {
                      "workOrderNumber": "2"
                   }
                },
                {
                   "lineItemName": "02 Site Utilities",
                   "unitCost": "2000",
                   "contractDetails": {
                      "activity": "20_null_9999"
                   },
                   "additionalCoding": {
                      "workOrderNumber": "2"
                   }
                }
             ]
          }
       }
    }

    Mapping I tried inside mapper:

    mapping expression I used:

    $items.map(val=>{"lineItemName":val.description,"unitCost":val.unitPrice,"contractDetails":{"activity":'20_'+jsonPath($,"items[*].projectActivity.chartCodes[*].chartCode").find(x=>x.supplementalType=='BOMA').uniqueCode+'_9999'},"additionalCoding":{"workOrderNumber":JSON.stringify($project.projectId)}})

    It gives me output as follows:

    {
       "order": {
          "orderLineItems": {
             "orderLineItem": [
                {
                   "lineItemName": "Architecture Fees",
                   "unitCost": "1000",
                   "contractDetails": {
                      "activity": "20_7845_9999"
                   },
                   "additionalCoding": {
                      "workOrderNumber": "2"
                   }
                },
                {
                   "lineItemName": "02 Site Utilities",
                   "unitCost": "2000",
                   "contractDetails": {
                      "activity": "20_7845_9999"
                   },
                   "additionalCoding": {
                      "workOrderNumber": "2"
                   }
                }
             ]
          }
       }
    }

    So here, I tried many a ways to manipulate the BOMA value which should come as distinct, the way it shows up in input, like for item 1 we have value available but for item 2 we should get null (or any other value, as coming from source), but the final working mapping I could figure out is mentioned above and it's basically mapping first BOMA code encountered in all the list object values.

    Appreciate any help here!

    Please let me know in case additional details needed here.

     

    Thanks,

    Deepti

    • alchemiz's avatar
      alchemiz
      Contributor III

      Hi Deepti ,

      Good day. Hope this helps

       

       

      {'order':{'orderLineItems': {'orderLineItem': $items.map( i=> { 'lineItemName': i.get('description'), 'unitCost': i.get('unitPrice'), 'contractDetails': { 'activity': ''.concat('20_', (i['projectActivity'].get('chartCodes',[]).find((x,y,z)=> x.get('chartCode',{}).get('supplementalType','') == 'BOMA') || {}).get('chartCode',{}).get('uniqueCode','null'), '_9999')}, 'additionalCoding': {'workOrderNumber': $project.get('projectId')} })}}}



      Thanks,

      EmEm

  • Deepti - please unzip and import the attached pipeline.  Since you are already familiar with jsonPath and Array functions, I will not go into detail on the solution.  Please let me know if you have any questions.  

    • Deepti's avatar
      Deepti
      New Contributor II

      Hi koryknick ,

      Thanks for your response, and I understood the solution provided, was following same path but couldn't make it work. However, I need to tweek this a bit further where I would need this projectid coming from outside also being mapped in items array list.

      {
         "order": {
            "orderLineItems": {
               "orderLineItem": [
                  {
                     "lineItemName": "Architecture Fees",
                     "unitCost": "1000",
                     "contractDetails": {
                        "activity": "20_7845_9999",
                        "workOrderNumber": "2"
                     },
                     "additionalCoding": {
                        "workOrderNumber": "2"
                     }
                  },
                  {
                     "lineItemName": "02 Site Utilities",
                     "unitCost": "2000",
                     "contractDetails": {
                        "activity": "20_null_9999",
                        "workOrderNumber": "2"
                     },
                     "additionalCoding": {
                        "workOrderNumber": "2"
                     }
                  }
               ]
            }
         }
      }

      So, if I want the output to look like this instead (where we have some elements from inside list and some from outside), then how will we achieve that as this is just the snippet of what I was looking for but, in reality I do need to combine some inside and outside array list objects. Looking forward to hearing back from you.

       

      Thanks & Regards,

      Deepti