remove number over four un json

  • Hello, i have a json file with geometry points
    to get a lightweight file i would to have not more four number after the coma, so remove the last two if there six nunbers etc
    how can i do
    thank a lot for your help

  • to give you more explanations

    in my json i have geometry points , like this


    before the . (point) it can be one or two x (same for y),
    and these x and y can be with -
    before … after the coma the number of x and y varies

    i would to keep only 4 numbers after the . (point)









    if you have ideas

  • @Pouemes44 ,

    Thank you for the example, because I would not have interpreted your original question in that way at all.

    So what you’re really saying is that you want to truncate any floating-point numbers to only four digits after the decimal. (Thank you for wanting truncation; that’s much easier than rounding – in fact, for the general case, true rounding requires a scripting solution rather than pure regex.)

    • FIND = (?<=\d\.\d{4})\d+
    • REPLACE = empty
    • SEARCH MODE = regular expression

    The FIND is using a lookbehind assertion (?<=...) to say that “what’s inside this assertion must come before”. Inside the assertion, it’s looking for a digit \d followed by a literal period \. (the \ is required to make the . be treated as a literal character instead of the special regex meaning of “. matches any character”), followed by four digits \d{4} (where {4} is a multiplying operator). After the assertion, it’s looking for one or more digits \d+ (+ is another multiplying operator). Because of the lookbehind, the digit+dot+four-digits aren’t part of the “match”, so only the 5th digit and beyond are part of the match – so only 5th digit and beyond get replaced with nothing (since the REPLACE is empty).




    Thank you again for the example data: showing examples of what should be changed and what shouldn’t be changed is very useful to give us things to test our example regular expressions before posting.

  • thanks Peter
    I will test

  • seems to work very well thanks Peter

  • done well works
    and now

    in some i have a space after the coma

    [-95.9606, 35.6226] or [5.4208, -147.1686]
    how to remove this space
    to get
    [-95.9606,35.6226] or [5.4208,-147.1686]


  • i have made this on you model, which seems to work





Log in to reply