Compare and Order 2 Json files

0

I would like someone's help to compare and sort 2 files: .JSON (each file contains more than 4000 lines when viewed in the notepad ++)

Let me explain:

File1.json (imagine that this file has everything in Portuguese after 2 points (:))

 var PT = {
    "xxx.yyy.Masculino": "Masculino",
    "yyy.yyy.Femenino": "Feminino",
    "yyy.yyy.Sexo_no_informado": "Sex"
              }  

File2.json (imagine that this file has its content all in English after 2 points (:))

var ING = {
    "yyy.yyy.Femenino": "Fem",
    "xxx.yyy.Masculino": "Muscle",
    "yyy.yyy.Sexo": "Sex"
         }  

Observation 1: If they are set correctly, the codes (on the left side of the 2 points, example: "yyy.yyy.Femenino") are not in the same sequential order among the files.

Observation2: I need you to show me if the codes are equal to the 2 values (PT and ING).

Ejemplo:  "xxx.yyy.Masculino": "Masculino", " Musculino " //son iguales no debo traducir
          "yyy.yyy.Femenino": "Feminino", "Fem" //distinto, debo traducir 

The idea is to be able to verify more easily, the differences to know if I should translate that field or not.

Any ideas on how to do this automatically? Since doing this Line by Line I lose a lot of time. Since I am grateful.

    
asked by Rodrigo Hackz Exploitz 10.10.2017 в 18:17
source

1 answer

0

I would recommend taking the json to c# classes where you can work ocn linq to join the info

What you should ensure is that both have the same properties, that is if one defines yyy.yyy.Sexo_no_informado and the other json yyy.yyy.Sexo this will not be able to be matched

Then you define the class based on the json helping you with

link

getting

public class RootObject
{
    public string xxx.yyy.Masculino { get; set; }
    public string yyy.yyy.Femenino { get; set; }
}

the idea is that using json.net

Newtonsoft.Json

deserializes the json to the class

using System;
using Newtonsoft.Json;


public class Program
{
    public static void Main()
    {
        string  PTJson = "{\"xxx_yyy_Masculino\": \"Masculino\", \"yyy_yyy_Femenino\": \"Feminino\", \"yyy_yyy_Sexo_no_informado\": \"Sex\" }";

        RootObject PT = JsonConvert.DeserializeObject<RootObject>(PTJson);

        string  INGJson = "{\"yyy_yyy_Femenino\": \"Fem\", \"xxx_yyy_Masculino\": \"Muscle\", \"yyy.yyy.Sexo\": \"Sex\" }";

        RootObject ING = JsonConvert.DeserializeObject<RootObject>(INGJson);


        Console.WriteLine(string.Format("xxx_yyy_Masculino = {0} {1}", PT.xxx_yyy_Masculino, ING.xxx_yyy_Masculino) );
        Console.WriteLine(string.Format("yyy_yyy_Femenino = {0} {1}", PT.yyy_yyy_Femenino, ING.yyy_yyy_Femenino));


    }

    public class RootObject
    {
        public string xxx_yyy_Masculino { get; set; }
        public string yyy_yyy_Femenino { get; set; }
    }


}

As you can see, you can obtain the values of each json to compare them with each other

Note: it is not valid to use point as property name, so replace by _

    
answered by 10.10.2017 в 21:22